“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条回答
在下西门庆
2楼-- · 2019-01-03 14:05

I had this issue when deploying on prod server only. In my other environments it works... I just deleted stuff in the bin folder then republish and it work after that.

查看更多
何必那么认真
3楼-- · 2019-01-03 14:06

This work for me: First thing: it's seem that no matter what did you say to visual studio, the ide always look the file in: bin (for web app and off course in my case) So, even when i said to visual studio a specific path to load file, the ide keep looking for the wrong path. So i change in the: Build/Configuration Manager the output type to: Release (previous i clean up the solution, even manually) so, when the file .dll was created then i moved manually to "bin" folder under the project/solution folder. Hope this will be helpfull !!

查看更多
狗以群分
4楼-- · 2019-01-03 14:07

In my case, It was because of my target processor (x64) I changed it to x86 cleaned the project, restarted VS(2012) and rebuilt the project; then it was gone.

查看更多
等我变得足够好
5楼-- · 2019-01-03 14:08

I was befuddled by the same darn issue. I tried to remove and and the global.asax (closed VS2010 before adding). Cleaned the project/solution, checked for any changes in the web application configuration and other stuffs that had worked for other people here in SO threads. I finally cleaned the solution, deleted the bin/obj folders and stopped any running VS2010 development servers then I reverted all the changes back and found the application was running again. I redid the same things and now its working fine.

Happened again and this time this solution worked for me.

查看更多
干净又极端
6楼-- · 2019-01-03 14:08

Just wanted to add my two cents. I was receiving the same error, and I tried all the suggestions to no avail. My situation is probably different?

Turns out, an auto-generated "AssemblyInfo.cs" file had some extraneous spaces, which was preventing me from launching the web app (via debug). Here's what the file looked like:

[assembly: AssemblyTitle("WebApplication2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("

            ")]
[assembly: AssemblyProduct("WebApplication2")]
[assembly: AssemblyCopyright("Copyright © 

             2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

After killing the spaces in the AssemblyCompany and AssemblyCopyright, I was finally able to build and launch the project.

Observed in the following environment: --Visual Studio 2017 Community version 15.3.0 --Win 7 x64 Enterprise --New Project > Visual C# > Web > ASP.NET Web Application > Web Forms

查看更多
仙女界的扛把子
7楼-- · 2019-01-03 14:09

If you rebuild or change a project and move over files from an old one, make sure to check the Inherit block of your global. In my case, the former project/solution was named intranet, and I had recreated it as Intranet, but when I moved over the files, it didn't like the lowercase (duh). Just do a general look-through of the names of the files.

查看更多
登录 后发表回答