247

I'm working on an MVC3 project and receive the following error:

Parser Error Message: Could not load type 'GodsCreationTaxidermy.MvcApplication'.

Source Error:

Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="GodsCreationTaxidermy.Core.MvcApplication" Language="C#" %>

The error I get is cannot load GodsCreationTaxidermy.Core.MvcApplication but in this screen shot the Core part isn't displaying in the error:

Error Page Screenshot

Does anyone have any ideas or a solution to this error?

10
  • 8
    Do you really have GodsCreationTaxidermy.Core.MvcApplication class in your application? If not please create the same and compile the project. It will work for sure.
    – Shailesh
    Commented Jul 27, 2012 at 6:00
  • 4
    Yes I do have GodsCreationTaxidermy.Core.MvcApplication (Global.asax.cs) Commented Jul 27, 2012 at 6:05
  • The Global.asax file that seems to be used (according to the screen shot) looks different than the one you have shown. Commented Jul 27, 2012 at 6:11
  • check to see if the Inherits string is the same as the path to the class in your application (namespace + pathname), that is they are both GodsCreationTaxidermy.Core.MvcApplication
    – linkerro
    Commented Jul 27, 2012 at 6:17
  • That's one of the issues Darin, no matter what I do it always leaves the Core part out Commented Jul 27, 2012 at 16:30

42 Answers 42

274

Check that the project output path (project properties / Build) is set to bin and not bin\Release or bin\Debug

For some reason IIS (VS development Server or Local IIS) always accesses the libraries from the bin directory (and won't look up for subdirectories)

7
  • 34
    Credit where it's due. Fixed my problem, my application was set to use bin\Debug, changing it to bin resolved it. Many Thanks.
    – Joey Bob
    Commented Sep 2, 2013 at 12:08
  • It was interesting to learn that ASP.NET projects do not use the default output path bin/$(Configuration)/. Many thanks for the answer! Commented Dec 23, 2013 at 15:40
  • 1
    Well this was messing it up. Dlls were going to bin\debug. Commented Aug 14, 2015 at 5:14
  • thank you !!! I was going crazy.. apparently another developer pointed the output to AppData\
    – Alex Z
    Commented Sep 17, 2015 at 17:59
  • 2
    @JamesPusateri: be careful though. Every time you launch, it will use what's in /bin. So probably the result of this one build you made after you changed it. Commented Oct 5, 2017 at 12:11
190

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.

11
  • 7
    Very strange error indeed. I deployed to IIS on server and got this. Cleaned and recompiled worked for me too.
    – Piotr Kula
    Commented Jan 14, 2014 at 21:15
  • 3
    Clean/Rebuild + re-created the Virtual Directory, and then it worked. Commented Dec 2, 2014 at 13:20
  • 5
    Had the issue when I had the same project open in two Visual Studio instances. Therefore I had two instances of IIS Express running. I had to close one and then it was resolved.
    – lvmeijer
    Commented Jun 5, 2015 at 14:28
  • 6
    You can also try deleting bin/obj folders in your project.
    – arni
    Commented Sep 2, 2015 at 14:57
  • 5
    I followed these instructions and threw in a few additional cleans/rebuilds, changed whitespace in the .asax file, reformatted my monitors, and did a jaunty jig accompanied by the pipes of Pan and that seemed to do the trick. Commented Nov 3, 2016 at 18:36
41

Try modifying your global.asax file (simple add a space somewhere) and re-run. this will force the built in webserver to refresh and recompile the global.asax file.

Also do a clean and rebuild - should fix the problem

3
  • 5
    Modifying global.asax didn't do anything for me, but a clean and rebuild fixed the problem :) Commented Jul 13, 2013 at 19:04
  • I had this problem when I ran out of power. Clean and rebuild helped. Thanks! Commented Nov 25, 2013 at 10:59
  • Clean failed. Build failed. I had no issues with my build path. This, however, did the trick. Thanks!
    – egandalf
    Commented Nov 18, 2015 at 23:37
35

This happens sometimes if you change namespace information (project or class level) after the global.asax is generated.

Right click on the Global.asax file and select "Open With" and then select "XML (Text) Editor with Encoding" (other editors may work as well, but this is what I use).

Then edit the "Inherits" section in the XML directive

<%@ Application Codebehind="Global.asax.cs" Inherits="GodsCreationTaxidermy.MvcApplication" Language="C#" %>)

so that it matches the actual full name of your Application class. And that's it.

Another option is to copy off all your code from Global.asax.cs and then delete and create another Global.asax file (and then copy the code back into Global.asax.cs).

2
  • This worked for me also. I'd changed the namespace for the assembly for all projects in the solution. So had to edit the Global.asax file as stated in this answer, and make it match what's in the Project Configuration settings.
    – Shiva
    Commented Feb 12, 2018 at 6:29
  • How do I find out what the full name is of my application class? I've tried everything to sort this out but it still isnt working. Losing my mind
    – paulr23
    Commented Oct 26, 2021 at 7:47
24

I closed and reopened visual studio and it worked.

4
  • 5
    close ALL your visual studio
    – jflaga
    Commented Dec 8, 2014 at 14:48
  • 15
    First we should all try getting out of the car, shutting all the doors, then getting back in again.
    – pajics
    Commented Oct 7, 2015 at 12:53
  • 3
    no, you have to close the doors on ALL your cars, at the same time.
    – BlackICE
    Commented Apr 9, 2020 at 13:46
  • Yes I needed to close the doors too.
    – Edward
    Commented Sep 17, 2020 at 17:31
22

I had to go to BUILD -> CONFIGURATION MANAGER and -- ahem -- check the box next to my project to ensure it actually gets built.

6
  • 4
    I don't understand the downvote. This could potentially have been a solution. This is actually more relevant than most think... If unchecked, it is not always the most obvious location. Especially when there are several configurations. Commented Jun 11, 2015 at 15:18
  • I like your answer and your reasoning!
    – UKM
    Commented Jun 14, 2016 at 17:17
  • 1
    This was my problem, too, and I have no idea how the projects got deselected from the configuration.
    – Seth
    Commented May 19, 2017 at 19:36
  • For me, my Active Solution Platform somehow got changed from "Any CPU" to "Mixed Platforms", where all the builds were unchecked. Switching back to "Any CPU" had the builds checked. Commented Mar 2, 2022 at 23:39
  • 1
    Tried all mentioned above solutions, but this one worked for me. Thanks
    – Areesha
    Commented Oct 18, 2022 at 16:54
7

I had this issue today, and it took me a while to find the cause.

Basically, my main VS2015 project was including a sub-project which had been built using a higher version of .Net Framework.

Bizarrely, when you have this problem, VS2015 will happily report that the solution has built okay, but when you try and run the website, it just gives you that misleading error, suggesting that your Global.asax.cs file is wrong.

So, if you see this error, and Cleaning/Rebuilding doesn't help, open your Project's References tree, and check for exclamation marks.

enter image description here

Also, check your Output window for messages like this:

The primary reference "C:\Projects\Business Objects 4\bin\Release\BusinessObjects.dll" 
could not be resolved because it was built against 
the ".NETFramework,Version=v4.5" framework. 
This is a higher version than the currently targeted framework
".NETFramework,Version=v4.0".

The solution, of course, is to right-click on your main project, select the top tab, "Application", and change the Target Framework version to a higher version which matches your sub-project.

It's annoying that Visual Studio 2015 will let you fully build and run Solutions which quietly contain this problem. It's asking for trouble..!

1
  • I have warnings like this, but I've not changed anything so I'm confused why rebuilding to a higher framework would resolve.
    – paulr23
    Commented Oct 26, 2021 at 8:10
5

I was working on an older 'folder based' ASP.NET web project (which I loathe) - and found this to be my fix:

Create an App_Code folder (if you didn't have one already)

Move the Global.asax.vb file into the App_Code folder

The markup in Global.asax can leave out any namespaces (at least, for this style of project, afaik):

<%@ Application Codebehind="Global.asax.vb" Inherits="MyApp" Language="VB" %>

...where "MyApp" is the name of the class being defined in Global.asax.vb

1
  • Perfect. As I don't use Visual Studio to maintain my websites, this is absolutely ideal. Commented Jan 11, 2022 at 17:46
4

I just encountered this on an MVC5 application and nothing was working for me. This happened right after I had tried to do an SVN revert to an older version of the project.

I had to delete global.asax.cs and then added a new one by right clicking Project -> Add New Item -> Global.asax and THAT finally fixed it.

Just thought it might help someone.

2
  • If that fixes it for you, there's probably something messed up about the "Build action" property of the existing global.asax.cs file. It should be set to "Compile". The build action of the global.asax file itself should be set to "Content". Commented Apr 16, 2015 at 8:27
  • I did exactly what @iAteABug_And_iLiked_it did, and the problem was solved!
    – zinczinc
    Commented Jun 4, 2018 at 11:14
4

"BUILD -> CONFIGURATION MANAGER and -- ahem -- check the box next to my project to ensure it actually gets built." That and going to the project folder in windows explorer, pressing options and unchecking the "Read only" checkbox helped.

1
  • simply it worked for me. The project has not has built option enabled I don't know why but this workaround was what I needed, thanks.
    – willyMon
    Commented Aug 31, 2018 at 3:27
3

Delete the .vs directory from the solution root. Clean. Rebuild.

This issue drives me bonkers once in awhile and I inevitably end up here paging through answers. I suspect there are multiple causes that can produce this exception, this once works for me.

2
  • Several hours of trying a thousand other suggestions and this is the one that did it for me. My application was running fine in Visual Studio, both in debug and release configurations, but once published to IIS I was getting the error. Deleting the .vs folder and re-deploying fixed the issue. Commented Mar 8, 2019 at 17:27
  • 1
    For anyone finding this, here are the exact steps 1. Close Visual Studio (It won't work if you skip this step) 2. delete the .VS file 3. Restart Visual Studio
    – Brad Bruce
    Commented Sep 2, 2020 at 13:02
3

Yes, I read all the answers. However, if you are me and have been pulling out all of what's left of your hair, then try checking the \bin folder. Like most proj files might have several configurations grouped under the XML element PropertyGroup, then I changed the OutputPath value from 'bin\Debug' to remove the '\Debug' part and Rebuild. This placed the files in the \bin folder allowing the Express IIS to find and load the build. I am left wondering what is the correct way to manage these different builds so that a local debug deploy is able to find and load the target environment.

2
  • This is the only thing that worked. So many buried bodies... it's stuff like this that makes me seriously consider other vocations.
    – doveryai
    Commented Jun 5, 2020 at 17:53
  • Well, I don't have a bin folder. I am working on a web site.
    – htm11h
    Commented Nov 16, 2021 at 21:19
2

You can also check your site's properties in IIS. (In IIS, right-click the site and choose Properties.) Make sure the Physical Path setting is pointing to the correct path for your application not some other application. (That fixed this error for me.)

2

Empty the bin folder. Build all the dependent class libraries and refer them in the main project, and build the complete solution.

Source

2

I have to report that I tried at least 4 suggestions from this post. None of them worked. Yet I am happy to report that I recovered by retrieving from back up. Only had to update my last code changes from log file. Took less then 10 minutes. Spent 3 times that reading this post and trying other suggestions. Sorry.

It was a very weird error. Good luck to anyone else encountering this gremlin.

2

I have same problem when I have 2 instance of Visual Studio running same project. So I closed both Visual Studio and opened only one instance and It works fine now!

2

I spent multiple days on this issue. I finally got it resolved with the following combination of suggestions from this post.

  1. Change platform target to Any CPU. I did not have this configuration currently, so I had to go to the Configuration Manager and add it. I was specifically compiling for x64. This alone did not resolve the error.
  2. Change the output path to bin\ instead of bin\x64\Debug. I had tried this several times already before I changed the platform target. It never made a difference other than getting an error that it failed to load the assembly because of an invalid format.

To be clear, I had to do both of these before it started working. I had tried them individually multiple times but it never fixed it until I did both.

If I change either one of these settings back to the original, I get the same error again, despite having run Clean Solution, and manually deleting everything in the bin directory.

2

I fixed error as below.

My .dll was copying in bin\Debug folder. because of these reason it was throwing Could not load type assembly.

Fix: I change the Project output path to build my dll's inside bin\ folder

 <OutputPath>bin\</OutputPath>
1
  • I changed the path to bin\debug\ jst because I needed to segregate the builds. Changed it back and it works again. I would love to know why!
    – David
    Commented Aug 16 at 9:11
1

This issue I was solved by giving right permission of the folder as well as check from IIS.

I was given permission to everyone as I am testing in my local environment. But in publish mode I think we give only permission to ASP.Net user.

1

I too faced the same problem. Despite of following every Answer it didnt work. Then I changed the "Inherits=namespace.class" to "Inherits=fully qualified assemble name" i.e "Inherits=namespace.class,assemblyname, Version=, Culture=, PublicKeyToken=" Hope it helps.

1

This can also happen if you accidentally forget to set your VS solution to "Multiple Startup Projects" if you are running a Web and WebApi from the same solution.

You can check this by right-clicking on Solution in the Solution Explorer and select 'Properties". Then look for 'Startup Projects'.

1
  • Mine was similar to this: I was running the wrong API project in the solution. I actually had a compiler error in the API I thought I was running, but VS didn't pick up on it when I ran the solution, even after a clean. Commented Dec 4, 2017 at 1:49
1

The solution for me wasn't any of the above. I had to delete (and not recreate) Global.asax and Global.asax.cs. These files existed in the folder, even though they weren't referenced in the project. Apparently the build still saw them. Since I use OWIN with Startup.cs, the Global.asax file was obsolete and there was no issue with deleting it.

0

I also got the same error...check the name of the Application you developed properly ie. the namespace and the assembly name alloted and also try physically changing the name of the folder created for the application, all of this should be same as the name in the above namespace present in the file global.asax

0
0

I also got the same error...check the IIS Configuration of your Virtual Directory and be sure that Properties - ASP.NET - ASP.NET Version is the same of Project Properties - Application - Target Framework. (That fixed this error for me.)

0

My app was built in an older version of VS, and didn't have a bin folder. I had upgraded it to a newer version, and had a nightmare getting it to deploy. I finally tracked this error down to the Project > Properties > Application. The Target Framework was set to 2.0; changing it on the server to match in the IIS Manager/App Pool solved the issue for me.

0

I found that changing the Namespace on the project, without refactoring that across the whole solution was my problem. Check your project Properties and see what your namespace is, ensure that lines up, across the board.

0

The problem for me is that I didn't include global.asax.cs in my project. And because I was copying files from a .net 4.5 to a 4.0 I didn't comment out lines that are not needed in 4.0. Because it was not included visual studio compiled it anyway without issues. But when I included it, it highlighted the lines that cause problems.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using System.Web.Http;
using System.Web.Mvc;
//using System.Web.Optimization;
using System.Web.Routing;

namespace YourNameSpace
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            //GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}
0

I spent literally a day trying to resolve this.

The only thing that worked was deleting the .sln file, creating a new one, and adding the projects back in one by one.

¯\_(ツ)_/¯ - Programming - ¯\_(ツ)_/¯

0

For my case, the web assembly was part of GAC... so after build, it need to installed in GAC and it worked.

0

I encountered this error message and eventually discovered that the error message was misleading. In my case there appears to have been a routing issue in IIS which caused the global.asax from another site on the web server to be read thus generating the error.

In IIS, my site was bound to http:*80:webservices.local and contained an application called MyAPI. I received the dreaded message when calling the MyAPI application using the web server's ip address.

In order to successfully call my application I had to add a host file entry for webservices.local on all of the machines that called the MyAPI application. Then all of my requests had to be prefixed with http://webservices.local/MyAPI/ in order to route correctly.

Not the answer you're looking for? Browse other questions tagged or ask your own question.