tags:

views:

30

answers:

3

I added a global.asax file, and later decided I didn't need it, so I excluded it from the project, but now I get a parser error when I attempt to run my project.

What happened and how do I fix it (besides the obvious of adding it back to the project)?

+1  A: 

try opening the project file in notepad, there is probably some references in there eg

<Compile Include="Global.asax.cs">
      <DependentUpon>Global.asax</DependentUpon>
    </Compile>
Pharabus
I liked this solution as well. Thanks.
A: 

If you excluded it, rather than deleting it, you should be able to re-include it again.

right click on the project, select Add Existing Item and navigate to the global.asax which should still be in the root directory of your project.

Clicktricity
+3  A: 

In an ASP.NET Web Application project, excluding Global.asax merely removes it from the .csproj file. It appears as a "hidden" file if you enable the "Show All Files" option on your project.

At any rate, your project ignores it and does not compile it, which is expected, but the web server recognizes the .asax file and attempts to load the class referenced in the <%@ Application @> directive. The class does not exist because it was omitted from the project.

To fool Visual Studio and the web server, consider also appending the extension .exclude to the Global.asax. Doing so keeps your file around (which I assume you intended), but ensures that the web server does not try to treat it as a global application class.

Of course, if you really don't want it around, simply delete the .asax file and, if applicable, the code behind.

kbrimington
Nice explanation. +1.
David Stratton