“Could not load type [Namespace].Global” causing m

2019-01-03 13:19发布

In my .Net 2.0 Asp.net WebForms app, I have my Global.asax containing the following code:

<%@ Application CodeBehind="Global.asax.cs" Inherits="MyNamespace.Global" Language="C#" %>

However when I build I get an error stating-

Could not load type 'MyNamespace.Global'.

This seems to be because the MyNamespace namespace (defined in the code behind file Global.asax.cs) is not seen by the compiler in the Global.asax file (does not show in R# intellisence..). This turned out to be a very hard nut to crack... any help will be appreciated!

Note: The Global.asax and the Global.asax.cs are located in the same folder.

Note2: When compiling from the vs prompt with csc it compiles o.k.

30条回答
forever°为你锁心
2楼-- · 2019-01-03 13:52

In my case, I had added Global.asax to a WCF project to experiment with it, but decided to remove it. I removed it from Solution Explorer, but because it was still in the folder, the pipeline was still finding it and causing this error.

I removed the Global.ASAX and GLobal.asax.cs from the filesystem and that did resolve the error.

查看更多
The star\"
3楼-- · 2019-01-03 13:56

Here's another one for the books. It appears that this happens when you launch more than one web application from the same port number.

Basically, I have a couple of branches that I work off, I have a main branch and a staging branch and a release branch. When I switched branch to the staging branch I noticed that it was using the same port address configuration so I opted to change that. I then received another warning that this reservation conflicts with another configured application. The IIS Express server is sensitive about that and for whatever reason it bricks the configuration.

By simply picking a third unaffected port this problem went away because it then maps the port to a new directory mapping (my branches are located differently on disk). I noticed this because I tried to change the type name pointed to by Global.asax but the type name was unchanged even after restarting the server, so clearly, the code I was changing wasn't reflected by the IIS Express deployment.

So, before you lose too much sleep over this, try changing the IIS port number that is currently used to run the web project.

查看更多
Lonely孤独者°
4楼-- · 2019-01-03 13:56

In my situation it was related to Web Site/Web Application type of the project. We recently moved to MVC and had to change it to Web Application.

So, the solution was simple: select your web-site in Solution Explorer and remove it from the solution, then right click on the solution and select Add -> Existing Project (not Web Site), recompile the web-site.

查看更多
家丑人穷心不美
5楼-- · 2019-01-03 13:57
  1. Right Click on Project Solution and Select Batch Build.
  2. Then select Your Project Name and Clean And Rebuild.

Works Fine For Me IN VS 2015.Now I can Use Global event. My Global.asax file has this Line

<%@ Application Language="C#" CodeBehind="~/App_Code/Global.asax.cs" Inherits="Global" %>

And I make class file Global.asax.cs that is in AppCode folder that look like

public partial class Global : HttpApplication
{
    public Global()
    {
        //
        // TODO: Add constructor logic here
        //
    }
}

I hope this will help

查看更多
你好瞎i
6楼-- · 2019-01-03 13:57

I experienced this problem when I accidentally set "Chrome" to be the default browser for debugging. When I set it back to "IE" the problem disappeared. I am not sure why...


EDIT: I was about to delete this answer, because I wasn't sure about it, but then I had the problem again. I switched to browsing with Chrome, then back again to IE and it stopped! What gives!?

查看更多
小情绪 Triste *
7楼-- · 2019-01-03 13:58

I had converted my solution from VS2003 to VS2010 and had had problems converting the web application project.

I experienced the exact same problem and none of the answers worked for me.

What worked for me was:

  • Right Click on the solution and select Configuration Manager
  • Looked at each of the configurations in the 'Active solution configuration' drop down list.
  • Included the web application in the build by ticking the 'Build' check-box.

it would seem that the problems I had during the conversion had removed the web application project from the build for some reason.

Hopefully this answer helps anyone else that has the same problem...

查看更多
登录 后发表回答