ASP.NET page directive causing errors

I have a page that exhibits the strangest behavior. When creating / debugging my project, I sometimes get build errors that point to my directive on the page.

If I insert extra space between any two attributes in the directive, the error disappears and the assembly succeeds.

Page Directive:

<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="true" CodeBehind="myPage.aspx.cs" Inherits="com.mycompany.UserControls.myPage" %> 

Resulting errors:

 Keyword, identifier, or string expected after verbatim specifier: @ C:\mypath\myPage.aspx 1 1 myProjectName A namespace cannot directly contain members such as fields or methods C:\mypath\myPage.aspx 1 1 myProjectName 

To repeat, for example, adding extra space between Page and Language="C#" temporarily clears errors. I will see a 100% chance of success in the next build, but the error will appear again. I often get an error by closing the editor that shows myPage.aspx and builds / restores my project.

Note. This behavior was present in Visual Studio 2008 and still remains after the transition to Visual Studio 2010.

Edit: Fixed a typo in which @ was omitted from the given page directive.

Any ideas?

+4
source share
2 answers

Are you missing the @ character between the opening keyword <% and the page? You

 <% Page Language="C#" AutoEventWireup="true" EnableSessionState="true" CodeBehind="myPage.aspx.cs" Inherits="com.mycompany.UserControls.myPage" %> 

and it should be

 <%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="true" CodeBehind="myPage.aspx.cs" Inherits="com.mycompany.UserControls.myPage" %> 
+3
source

Your missing @ character on page <% @Page ......

+1
source

All Articles