I'm currently working on an ASP.NET 4.0 site using a project-less solution.
By default the global.asax does not have a code-behind file, but after I changed it to
<%@ Application Language="C#" Co开发者_如何学GodeBehind="Global.asax.cs" Inherits="MyNamespace.Global" %>
And created an empty Global.asax.cs with the same namespace / class name I'm getting this error at compile time
Error 1 Could not load type 'MyNamespace.Global'. C:\Projects\RiskOptix\Code\RiskOptix.WebApplication\RiskOptix.WebApp\Global.asax 1
I've already tried cleaning out my entire bin folder but to no avail - this is extremely infuriating.
This question has already been asked. Check out this answer. Web site projects work differently from web application projects. Website type projects do not have CodeBehind
files instead have CodeFile
.
<%@ Application CodeFile="Global.asax.cs" Inherits="MyNamespace.Global" Language="C#" %>
CodeBehind = Needs to be compiled ( asp.net 1.1 model) and compiled binary is placed in the bin folder of the website. You need to do a compile in visual studio before you deploy. Good model when you do not want the source code to be viewable as plain text ... for example when delivering to a customer who you not have obligation to provide code.
CodeFile = You provide the source file with the solution for deployment. ASP.NET 2.0 runtime compiles the code when needed. The compiled files are at Microsfot.NET[.NET version]\Temporary ASP.NET Files.
I was not able to run my MVC Web application. It was giving Could not load type <application namespace.Classname>
error in Global.asax
I went to Project Properties
and set the build>output
folder to bin/
which was bin/Debug
. Ran it once. It ran fine. And then again set the output folder to bin/Debug
. Working fine now.
just to add my 2 cents with a WTF moment, My version of this error was caused by the Global.asax.cs not being included in the Visual Studio Project.
Right clicked on the .cs file, include in project and voila...
HTH
Dave
Yet another way to get this into this problem...
I had my web app open in VS2010, and IIS Express could run it just fine. Later, I opened the same web app, but in a newer branch with VS2012, and the virtual dirs in IIS Express auto-magically updated themselves to the physical dirs for the VS2012 project, without warning. So when I hit F5 to run my web app in VS2010 where I'm debugging, then I got the "could not load type or namespace" error in the global.asax file on one Import Namespace
line. Closing both VS instances and reopening just the VS2010 version fixed the problem.
精彩评论