Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 702
xelco52 Avatar asked Jul 03 '12 16:07

xelco52


People also ask

Which is the best way to handle errors in net?

You can handle default errors at the application level either by modifying your application's configuration or by adding an Application_Error handler in the Global. asax file of your application. You can handle default errors and HTTP errors by adding a customErrors section to the Web. config file.

What is exception handling in asp net?

Exception handling is an in-built mechanism in . NET Framework to detect and handle run time errors. Exceptions are defined as anomalies that occur during the execution of a program. The . NET Framework provides a rich set of standard exceptions that are used during exceptions handling.

What is custom error in asp net?

OFF: ASP.NET uses its default error page for both local and remote users in case of an error. ON: Custom error will be enabled for both local as well as remote client. REMOTE ONLY: The custom error page will be shown to a remote user only, the local user will get the built-in error page.


2 Answers

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" %>
like image 133
Richthofen Avatar answered Oct 21 '22 15:10

Richthofen


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

like image 1
HatSoft Avatar answered Oct 21 '22 14:10

HatSoft