ASP.NET how to resolve CS1513: } expected error on page

Tiger picture Tiger · Feb 23, 2012 · Viewed 26k times · Source

I am getting an error at run time when viewing my ASP.NET page in the browser. I am not getting any build errors however I am getting the following compiler error at runtime:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1513: } expected

Source Error:


Line 329:            #line hidden
Line 330:            __output.Write("\r\n\t\t\t</div>\r\n\t\t");
Line 331:        }
Line 332:        
Line 333:        private System.Web.UI.Control __BuildControl__control7() {

Source File: c:\Windows\Microsoft.NET\Framework\v1.1.4322\
    Temporary ASP.NET Files\xxxxxxxx\450ffa78\d46d847d\
    k1gsz9dj.0.cs    Line: 331 

I cannot locate any missing } in my source code and this error is occurring in the generated code files that exist in the Temporary ASP.NET Files directory. How can I trace this to the line of code that is actually malformed in my page or user controls on my page?

Answer

Suresh Mahawar picture Suresh Mahawar · Nov 13, 2013

If the error code related as following:

A variable name same as reserved word then you can rename variable.

A code segment such as:

@model MyModel
{
    var appname = @Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp);
}

Remove '@' coming before Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp)

A code segment or section usage such as:

@section{ 
    <!-- hiiii it's not about an error -->
}

Remove the apostrophe from comment in section.

If it is none of these specific cases you can attempt to locate where the error is generated by applying a source reduction. Delete/cut/comment out pieces of code until you can reliably turn the error off and on. The code that turns the error on is likely the culprit if it is not one of the above situations.