Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET: CS1519: Invalid token 'this' in class, struct, or interface member declaration

Tags:

c#

asp.net

When attempting to load in a browser an ASP.NET web form (.aspx page) that I'm working on, I get the following runtime error:

Server Error in '/' Application.

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: CS1519: Invalid token 'this' in class, struct, or interface member declaration

Source Error:

Line 447: #line default
Line 448: #line hidden
Line 449: this.@__PageInspector_EndRenderTracing(new object[] {
Line 450: @__w});
Line 451: this.@__PageInspector_BeginRenderTracing(new object[] {

The code quoted in the error message doesn't appear in any of my own code.

My project builds ok.

What's the cause of this error?

like image 594
Jon Schneider Avatar asked Dec 15 '22 09:12

Jon Schneider


1 Answers

In my situation, this error was caused by an extra/unbalanced closing curly bracket ("}" character) in a server-side code block in my .aspx file.

In other words, this error can be reproduced by creating an empty ASP.NET web form, and then inserting the following into the .aspx page somewhere:

<% } %>

I hadn't initially noticed, but despite the project building ok, Visual Studio was also reporting an error in the "Error List" window for my .aspx page: Type or namespace definition, or end-of-file expected

Tracking down the extra "}" character, deleting it, and reloading my page in the browser fixed the problem for me.

like image 62
Jon Schneider Avatar answered Dec 29 '22 14:12

Jon Schneider