Compilation error CS1647 when opening a large aspx file in a browser

I use XML / XSLT to create an aspx page that can grow quite large. Despite the fact that the file was successfully created when the file size approaches 300K, an error occurs: "CS1647: expression is too long or difficult to compile" is issued when the file is opened in the browser (both IE and Chrome have been tried). No other useful information is displayed on the .NET error page.

My development environment is VS 2012 Express for the Internet on a Win7 x64 laptop.

Since this problem does not occur during program execution, I do not understand how to approach this problem. Can anyone suggest a strategy or solve this problem?

EDIT

C # code used to create an aspx page,

// load the xml file XmlDocument reportDetails = new XmlDocument(); reportDetails.Load(ReportDetailsPath); //setup the xslt transform XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load(XlsRptPath); StringWriter sw = new StringWriter(); xslt.Transform(ReportDetails, null, sw); //create the aspx file using (StreamWriter outfile = new StreamWriter(aspxPath)) { outfile.Write(sw.ToString()); } 
+7
source share
2 answers

I apologize for not publishing my decision earlier, but at that time I was too cramped. Better late than never think.

Instead of creating a complete aspx web page for each xml file associated, I created a stub and applied the xslt conversion at runtime from the associated Site.Master. The MasterPageFile stub property is set on this Site.Master. This approach sacrifices some performance, but it works on any web page of size. Below is an example webpage .

Example aspx stub file:

 <%@ Page Title="Top Austin Beauty Salons List" MetaDescription="List of best Google-ranked Austin beauty salon" Language="C#" MasterPageFile="~/Site1.Master" %> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> </asp:Content> 

Site.Master Page_Load:

  protected void Page_Load(object sender, EventArgs e) { string vp = Page.AppRelativeVirtualPath; if (vp.ToLower().EndsWith("default.aspx") || vp.ToLower().EndsWith("webform2.aspx")) return; // ignore some aspx files used for ohter reasons string xmlPath = Page.MapPath(vp.Substring(0, vp.LastIndexOf(".")) + @".xml"); string xslPath = Page.MapPath("mainpage.xslt"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlPath); XsltArgumentList argsList = new XsltArgumentList(); argsList.AddParam("xmlPath", "", xmlPath); XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load(xslPath); // Execute the transform and output the results to a string writer. StringWriter sw = new StringWriter(); xslt.Transform(xmlDoc, argsList, sw); content.InnerHtml = sw.ToString(); // add the generated html to the associated stub aspx content section } 
+1
source

Old question, and basically answered in the comments. But for the sake of completeness, answer it;). Your problem is not with XSLT itself, but with the generated file, which removes the border of the maximum size of an expression of 300 KB in C # . There are a few things you can do:

  • Create the generated code below 300 thousand (but this may not be possible in your case)
  • Take any string constants in the generated code and put them in the resource file. The format of such resource files is XML, and you can automatically generate it, just make sure that the identifiers in the resource match the Identifiers that you use in the generated ASPX
  • Place part of the generated code in the code file. ASPX - this is parsed as a single expression, but the code is not behind. This is a matter of structuring the generated code.
  • Divide ASPX into multiple pages if your design allows it. You can recombine them with an iframe.
  • Split an .aspx file into multiple ASCX controls. Perhaps this is the most natural item. Each ASCX control can be referenced / added to an ASPX file. Each ASCX control must not exceed a limit of 300,000.
  • If there are a lot of generated CSS that exploded the size, put it in a separate CSS file.
  • If there are many long absolute paths in image links, for example, you can collapse them and make the links relative, that is, using <base> , which can save you some space.
  • If the error is caused by valid large (constant) expressions, consider the prompt answers in this message for resolution.
+1
source

All Articles