248
votes

I am getting the error

Could not load type MvcApplication

when I try to run my website.

How to correct it?

30
I got this error randomly one day on our build server. doing a manual rebuild resolved it. - Zack
The Output path is set in the project properties on the build tab - silasdavis
delete global.asax file and add a new one, and you will be alright. - DotNetGeek
It turns out that the new project was not selected in the active configuration for build. - JGeerWM
If you recently added the project or if you recently changed the publish configuration (i.e. switched from AnyCPU to x64) then it might be that the project is not built when you run it. Go to BUILD-> CONFIGURATION MANAGER and check the build column has the check box ticked. I have just had this issue now You will also notice that your breakpoints are clear circles when running the application. I think this is a result of the default build for .net 4.5.1 on processor architecture favouring 32 bit. Only an issue if you check x64 - David Bridge

30 Answers

116
votes

As dumb as it might sound, tried everything and it did not work and finally restarted VS2012 to see it working again.

107
votes

-For me, the fix was to change the output path in the build tab. I changed the output path to bin\ and the error went away.

-Another fix could be that you have the wrong start up project set.

83
votes

I was getting the same error and inspite of doing everything mentioned here and elsewhere nothing worked. Turned out that I had copied the source code of global.asax.cs from a previous version of the project which had a different name. So the namespace Test should have been namespace Test.WebUI. A silly mistake of course and am a bit embarrassed to write this! But writing in the hope that a similar error from anyone else may lead him to check this trivial aspect as well.

53
votes

Just do a manual build on your solution.

If you are using local IIS try deleting the website registration in IIS manager and then recreating it manually.

32
votes

[Extracted from question]

If you are getting this error: "Could not load type MvcApplication", look at the Output path of your project and make sure it is set to 'bin\'. The problem is that the AspNetCompiler cannot find the files if they are not in the default location.

Another side effect of changing the output folder is that you will not be able to debug your code and it comes up with a message saying that the Assembly info cannot be found.

16
votes

I had the same issue and solved it with below steps

  1. Go to project properties
  2. On the "Build' tab, set output path to "bin\"
14
votes

My solution: Because I created the problem! I had changed the namespace in Global.asax.cs

You also need to change the Inherits attribute value in the Global.asax.

14
votes

Ahh this was annoying.

Got this error after a power cut and i returned to my project.

I tried restarted VS. I tried setting the output path to \bin. I checked my name spaces.

But what worked for me was rebuilding the solution.

Rebuild Solution!!!

9
votes

Check code behind information, provided in global.asax. They should correctly point to the class in its code behind.

sample global.asax:

<%@ Application Codebehind="Global.asax.cs" Inherits="MyApplicationNamespace.MyMvcApplication" Language="C#" %>

sample code behind:

   namespace MyApplicationNamespace
    {
        public class MyMvcApplication : System.Web.HttpApplication
        {
            protected void Application_Start( )
            {
                AreaRegistration.RegisterAllAreas( );
                FilterConfig.RegisterGlobalFilters( GlobalFilters.Filters );
                RouteConfig.RegisterRoutes( RouteTable.Routes );
                BundleConfig.RegisterBundles( BundleTable.Bundles );
            }
        }
    }
7
votes
  1. Right click on the project within the solution that is failing.
  2. Unload Project
  3. Reload Project
  4. Build Project
  5. Re-build Solution
5
votes

This can also happen while running the project in visual studio if your IIS Express has/is hosting an old/different project using the same port assignment.

To fix this, you can change the port assignment for this project or close IIS Express.

5
votes

If you're hosting in IIS express and you open your project in two different locations, then you might see this error.

The solution is to go to Project/Properties/Web/Servers and click Create Virtual Directory.

4
votes

Delete the contents of the site's bin folder (use file explorer for this). Rebuild.

4
votes

The solution for me was to right click on the Mvc project, choose properties and click Create Virtual Directory.

A message box popped up saying that the project was mapped to the wrong folder (it showed the folder for a different TFS project. It gave the option to map it back to the correct folder.

4
votes

I already had bin/ in my build tab. I got global.asax from another copy of the project, but that didn't work out.

The solution that finally worked for me was to remove the bin/ folder and create a new empty folder with the same name.

4
votes

I know there are lots of solutions to this already, but I thought I'll just mention what solved it for me.

My configuration was set to Debug. Changing it to Release did the trick for me.

3
votes

I was getting this error because I was running the project despite some compile time errors. This I didn't notice.

3
votes

I have fallen into this. I have read and tested all the possible solutions that were given before. Checking build path, build, rebuild, clean, restarting IIS and VS2015, reinstall all nuget packages, compiling them one by one, etc,...

I suddenly remembered that VS keeps some ASP temporary files in system folders... I think I should give it a try, after all, that could get no worse. So I emptied:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

And all is working again... Weird that this problem has such different possible solutions...

3
votes

I've seen this many times over the last decade and just had it again. There are many problems that result in the same error.

One cause is a renaming of files. If you're working with .cshtml files, check all namespaces within those files and within the Views\web.config file. For web forms, rename Default.aspx (related .cs and designer files are automatically renamed). The codebehind changes but the Inherits line in the markup doesn't. Change it manually. Double check the designer page. Sometimes (VS2005-8?) the designer page doesn't reflect a change in the namespace. Haven't seen this in 2010+.

Another issue is when it all works in VS or on your local PC but not when you deploy. This could be because the deployment environment isn't structured the same. For example, the error occurs if you place your code in a virtual directory under an application folder, but it doesn't occur if you create a new application folder and place all of your files in there. I don't understand this one, as I've had the new child/virtual folder set with the same permissions (or so I think) and (I believe) the application pool should work the same for everything in a given application folder.

In my case I've also had a bin folder with assemblies that are updated from other assemblies on the IIS server. Again, ensuring that these are run in a separate application folder resulted in success.

HTH

2
votes

I get this problem everytime i save a file that gets dynamically compiled (ascx, aspx etc). I wait about 8-10 seconds then it goes away. It's hellishly annoying.

I thought it was perhaps an IIS Express problem so I tried in the inbuilt dev server and am still receiving it after saving a file. I'm running an MVC app, i'm also using T4MVC, maybe that is a factor...

2
votes

I had this frustrating error in development environment in Visual studio, and turned out the reason was quite dumb. In short if you have more than one web projects/sites in solution: make sure that the port you are trying to access the website is the same as configured in the Project Properties->Web

In my case, the error was caused because I was using a different port to access the website (in the browser) while the project in solution was assigned another port. To explain a little bit more, I had two website projects in my solution Website1(assigned port 8001 in ISS by Visual-Studio) and Website2(assigned port 8101 in ISS by Visual-Studio). So even though I was building Website1, I was trying to access the website using locahost:8101.

Now that I finally realized the problem, I see that @StingyJack's comment addresses the similar issue as well.

2
votes

Make sure the namespace in your global.asax.cs matches the namespace of your webapp

2
votes

I had this error again and none of the above worked for me. I had to remove the following node in .csproj file: <VisualStudio>....</VisualStudio>. Reloaded VS and it worked.

FYI, VS was able to recreate the node and then I recreated the website in IIS (through VS) and it worked perfectly.

Hopefully this will help someone.

1
votes

Make sure you shouldn't have to open the MVC project like File->Open Web Site use File->Open Project instead.

1
votes

What worked for me was restarting Visual Studio.

I tried manually rebuilding, performing a clean and rebuild, and deleting the bin folder all of which did not work. My output path was already set to bin\

1
votes

If you changed a namespace make sure to right click and refactor.

1
votes

This could happen very often if you change your namespace. Return the name of your namespace,just like it used to be, and that should make it work!

1
votes

In some circumstances, new projects you create are not by default set to build. If you right-click on your solution, choose Properties, and choose the Configuration Properties | Configuration node on the left and ensure your project has a checkmark under the Build column. In normal circumstances I've found this happens by default. In other circumstances (I happen to have a somewhat complex Web Api / Xamarin Android and iOS / Mvc 5 solution that exhibits this behavior) the checkmark isn't present.

This is related to the other answers -- if your web projet's assembly is unavailable, you get this error. But this might be a common scenario, especially since you do in fact compile your solution -- the project just doesn't get built.

1
votes

I got this error because my version control had gotten set to ignore my bin folder. Very stupid, but maybe someone else will benefit.

1
votes

I ran into this very problem and I see there all kinds of answers but nothing has been accepted. I after a little bit discovered that simply building the website before trying to run solved my problem.