xelco52
xelco52

Reputation: 5347

ASP.NET Page directive causing errors

I have a page that is exhibiting the strangest behavior. When building/debugging my project I will sometimes receive build errors pointing to my page directive.

If I insert an additional space between any two attributes in the directive, the error goes away and the build 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 reiterate, for example, adding an additional space between Page and Language="C#" temporarily clears the errors. I will see a 100% success rate on the next build, but the error will eventually reappear. I can often force the error by closing the editor that is showing the myPage.aspx and building/rebuilding my project.

Note: This behavior was present in Visual Studio 2008, and still remains after a switch to Visual Studio 2010.

Edit: Corrected typo where @ was omitted from page directive in question.

Any ideas?

Upvotes: 5

Views: 4358

Answers (2)

HatSoft
HatSoft

Reputation: 11201

Your missing @ symbol in your <%@ Page......

Upvotes: 1

Richthofen
Richthofen

Reputation: 2086

Are you missing the @ symbol between the opening <% and the Page keyword? You have

<% 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" %>

Upvotes: 4

Related Questions