[c#] "Could not load type [Namespace].Global" causing me grief

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.

This question is related to c# asp.net webforms namespaces global-asax

The answer is


I've run across this issue a few times and in each case I was rebuilding a computer or switching to a new computer. My first step (besides updating the machine and installing Visual Studio) is to pull my projects down from Git and test them.

I hit this error each time because I tried to access my local code before compiling it. You see, I have Git and Subversion setup to ignore my bin/build folders, so after a pull from my repository I forgot to run a build which pulls required packages from Nuget (since I have Git/SVN ignore those too) and creates the DLLs needed to actually run my app.

I doubt this will resolve most people's issues, but I didn't see it on the list of potential solutions so I thought I'd add it.


Change the GUID of the assembly. This fixes many MANY problems, I have found.


I've tried to rebuild solution and clear ASP.NET Temporary files without success.
But after run IISRESET the error disappeared.

Update: I had the same problem again 1 month later. I've noticed that MyWebsite.DLL exists in bin folder, but doesn't exist in Temporary ASP.NET Files (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files). I've tried a few things, that are suggested on this and "Parser Error Message: Could not load type" in Global.asax questions (I actually forgot about my own answer), but the error disappeared again only after IISRESET


Check the Build Action of Global.asax.cs. It should be set to Compile.

In Solution Explorer, Right-click Global.asax.cs and go to Properties. In the Properties pane, set the Build Action (while not debugging).

It seems that VS 2008 does not always add the .asax(.cs) files correctly by default.


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.


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.


Have you changed the namespace of your project? I've seen this happen occasionally where I've changed the namespace in the Project Properties dialog but Visual Studio hasn't changed the namespace declaration in existing code files.


I experienced a similar error when having a

<clear/>

tag as a child (the first child) of the

<assemblies>

tag in my Web.config. I had inserted the tags in my web.config in an attempt to prevent configuration inheritance in an application deployed under the 'Default Web Site' in IIS.


in my case it was IISExpress pointing to the same port as IIS to solve it go to

C:\Users\Your-User-Name\Documents\IISExpress\config\applicationhost.config

and search for the port, you will find <site>...</site> tag that you need to remove or comment it


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.


Having been in the development game for almost 20 years, this chestnut has continued to plague me across multiple projects.

As such, today whilst experiencing this same problem again, against another project, I decided to investigate further and I do believe this is related to Bin folder location... or more specifically, the output path of the bin folder.

For me, for a simple service based web application configured to run/debug through IIS, it was changing the output path from bin\debug to bin\ that resolved it

Project > Properties > Build > Output path

Seriously hopes this helps.


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...


If you are using Visual Studio, You probably are trying to execute the application in the Release Mode, try changing it to the Debug Mode.


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.


I restarted Visual Studio and error was gone!


You need to set your Output path to bin\


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.


As silly as it may sound. Here is what I did..

My project was targeting 4.6.1 version. Changed the target version to 4.6.2. built it. deleted obj & bin folders. & once again changed the version to 4.6.1. Bingo!!


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 !!


go to configuration Manager under properties for your solution. Then make sure all projects and getting built, and this won't be a problem.


When I encountered this problem most recently I tried everything mentioned here but to no avail. After tearing my hair out I decided to try deleting my entire code base (yes, pretty desperate!) and then re-downloaded everything from my code repository. After doing this everything worked fine once more.

Seems an extreme solution but just thought I'd include it here as it hasn't been mentioned before in this thread.

(Note that the other time I have encountered this issue, is when the Global.asax was inheriting from a component which needed to be registered on the host machine. This was missing hence I got this same issue).

TL;DR; If all answers in this thread don't work for you, try deleting and then re-downloading your entire code base!


None of these worked for me, unfortunately. The fix I found was more specific to development, specifically, debugging on your local machine. Also unfortunately, it doesn't really fix the issue in the way I was hoping, but if you're at your wit's end, this might get you running again.

TL;DR: In the project properties, in the web tab, under Servers, Select Use Local IIS Web Server. The address,

http://localhost/MyApp" 

was already populated (I have IIS7, .NET 4.0). What was originally selected was the "Use Visual Studio Development Server" with a Virtual path of "/"

What's really puzzling to me is the fact that nothing else worked, I went through all of the suggestions I could find on SO, and nothing would work. The weird thing is, the error was (seemingly, it's been a few months since I last looked) manifested when I added a new ascx file that was similar to an existing one that was added from an old .net 2.0 (I think) project that would allow for custom user management from within the application. It was working, beautifully, for a long time, until I tried adding this new file. After adding it, and seeing the error, I promptly reverted all changes, but the Global.ascx error would not go away, not even blowing away the whole project and re-getting latest from source control.


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!?


Well In my case VS 2017, the lightweight solution load was causing this issue. I disabled it & restarted VS then re-build my solution & the problem gone.


Old post but I go this error when trying to convert from website project to web application project.

Follow the instructions on this Link. I still got the global.asax error but all I did was delete it and re-add it back by right clicking on the project in visual studio and selecting add new item. Add the global.asax file and it worked.


I am new to asp .net developement and I faced the similar problem.

I updated the class as a partial class and it worked fine.

public partial class Global : System.Web.HttpApplication

  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 had to delete (duplicate) files from disk that were not included in the project. Looks like the duplicates were caused by a failed rename. The file names were different, but same code.

After deleting all the oof.* files I was able to scan.

  • foo.aspx
  • foo.aspx.cs
  • foo.aspx.designer.cs
  • oof.aspx
  • oof.aspx.cs
  • oof.aspx.designer.cs

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


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.


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.


I had a similar issues where I was receiving this error on a project.

“Could not load type [Namespace].Global
Error in Line 1   etc etc

After spending some time I suspect a function with possible errors in a Class ..later commenting that specific function my problem get resolved.

I dont know why Visual Studio did't give me that specific error at debugging time. But this error might occure due to some errors in class file..


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to webforms

ASP.NET Button to redirect to another page How to use the DropDownList's SelectedIndexChanged event "Specified argument was out of the range of valid values" The ScriptManager must appear before any controls that need it Check if Cookie Exists How to do a Jquery Callback after form submit? "The given path's format is not supported." A potentially dangerous Request.Path value was detected from the client (*) How to create <input type=“text”/> dynamically Create a HTML table where each TR is a FORM

Examples related to namespaces

Class 'App\Http\Controllers\DB' not found and I also cannot use a new Model How do I get an object's unqualified (short) class name? socket.error:[errno 99] cannot assign requested address and namespace in python What is the use of "using namespace std"? Visibility of global variables in imported modules Using :: in C++ 'namespace' but is used like a 'type' type object 'datetime.datetime' has no attribute 'datetime' Why am I getting error CS0246: The type or namespace name could not be found? string in namespace std does not name a type

Examples related to global-asax

Multiple HttpPost method in Web API controller Where is the Global.asax.cs file? "Could not load type [Namespace].Global" causing me grief