"Could Not Load Type [Namespace].Global" Causing Me Grief

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

One situation I've encountered which caused this problem is when you specify the platform for a build through "Build Configuration".

If you specify x86 as your build platform, visual studio will automatically assign bin/x86/Debug as your output directory for this project. This is perfectly valid for other project types, except for web applications where ASP.NET expects the assemblies to be output to the Bin folder.

What I found in my situation was that they were being output to both (Bin and Bin/x86/Debug), with the exception that some of the dll's, and inexplicably the most important one being your web application dll, being missing from the Bin folder.

This obviously caused a compilation problem and hence the "Could not load type Global" exception. Cleaning the solution and deleting the assemblies made no difference to subsequent builds. My solution was to just change the output path in project settings for the web app to Bin (rather than bin/x86/Debug).

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

One situation I've encountered which caused this problem is when you specify the platform for a build through "Build Configuration".

If you specify x86 as your build platform, visual studio will automatically assign bin/x86/Debug as your output directory for this project. This is perfectly valid for other project types, except for web applications where ASP.NET expects the assemblies to be output to the Bin folder.

What I found in my situation was that they were being output to both (Bin and Bin/x86/Debug), with the exception that some of the dll's, and inexplicably the most important one being your web application dll, being missing from the Bin folder.

This obviously caused a compilation problem and hence the "Could not load type Global" exception. Cleaning the solution and deleting the assemblies made no difference to subsequent builds. My solution was to just change the output path in project settings for the web app to Bin (rather than bin/x86/Debug).

Parser Error Could not load type [namespace].Global

I was finally able to sort out what was wrong. We spun up an old VM that had a working copy of the software in question, but didn't have the other websites on it. We were able to point our production floor at the VM so their work was unimpeded. Then the question came up, how difficult would it be to get the other websites up and running on the VM as well? Well, as it turned out not too difficult, but there were several challenges, specifically enabling 32 bit applications, setting a default page, and disabling form authentication. Once I got those set to match the settings on the live server, I was able to get the new sites to show up successfully on the VM. So, I worked the problem with the original site backwards using nearly the exact settings, and voila, the site started working.

Throughout the debacle last week I know I tried all of these with the exception of the default page (our short cuts to the various websites all have specific page names, so it wasn't necessary). I guess I just never tried them in the right combination until last Friday.

Hopefully this helps someone else out there to add to yet another bunch of things to try when dealing with a parser error.

What does could not load type Namespace.Module mean?

The issue seems to be that you need to change CodeBehind with CodeFile. For information on why you can visit this other post:

CodeFile vs CodeBehind

Parser Error Message: Could not load type in Global.asax

Your local web server is running different code than what you're actually working on. Ensure you have stopped debugging, stop your local web server, clean and rebuild as Peter suggested, double-check your global.asax and global.asax.cs, and try again.

If this doesn't work and you are using local IIS, try removing the site in IIS Manager and recreating it manually.

could not load type MyNameSpace.Global

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.

Could not load type 'XXX.Global'

There are a few things you can try with this, seems to happen alot and the solution varies for everyone it seems.

  • If you are still using the IIS virtual directory make sure its pointed to the correct directory and also check the ASP.NET version it is set to, make sure it is set to ASP.NET 2.0.

  • Clear out your bin/debug/obj all of them. Do a Clean solution and then a Build Solution.

  • Check your project file in a text editor and make sure where its looking for the global file is correct, sometimes it doesnt change the directory.

  • Remove the global from the solution and add it back after saving and closing. make sure all the script tags in the ASPX file point to the correct one after.

  • You can try running the Convert to Web Application tool, that redoes all of the code and project files.

  • IIS Express is using the wrong root directory (see answer in VS 2012 launching app based on wrong path)

Make sure you close VS after you try them.

Those are some things I know to try. Hope one of them works for you.

Parser Error Message: Could not load type in Global.asax

Your local web server is running different code than what you're actually working on. Ensure you have stopped debugging, stop your local web server, clean and rebuild as Peter suggested, double-check your global.asax and global.asax.cs, and try again.

If this doesn't work and you are using local IIS, try removing the site in IIS Manager and recreating it manually.



Related Topics



Leave a reply



Submit