Created On:  16 December 2010

Problem:

An ASP.NET web application builds succesfully in Visual Studio but when trying to run or debug the application strange compiler error messages occur which point to source code in the App_Code subfolder or in temporary files.

Resolution:

The problem you are seeing is because you have an App_Code folder, which gets compiled at run-time and is only expected to be part of a Web Site, not a Web Application which is precompiled.

What is happening is that the contents of the project, including the classes in App_Code, get built to an assembly but at run-time the ASP.NET server
is compiling the contents of App_Code and specifying references to all of the project references plus the project output.

That means that the compiler is attempting to compile classes with a reference to compiled versions of themselves and not surprisingly it is getting rather confused hence the strange error messages.

If you rename your App_Code folder to a different name then the Web Project will run.