251

I am getting the error

Could not load type MvcApplication

when I try to run my website.

How to correct it?

10
  • 38
    I got this error randomly one day on our build server. doing a manual rebuild resolved it.
    – Zack
    Aug 14, 2009 at 21:27
  • 9
    delete global.asax file and add a new one, and you will be alright.
    – DotNetGeek
    Jul 8, 2013 at 7:51
  • 4
    It turns out that the new project was not selected in the active configuration for build.
    – JGeerWM
    Jan 28, 2015 at 19:11
  • 5
    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 Jul 22, 2015 at 9:29
  • 4
    Judging by all the various ways people got this to work for them, it seems like the best solution is to mash keys and flip power switches on and off very rapidly and perhaps threaten the computer. Sep 7, 2016 at 15:30

43 Answers 43

120

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

6
  • 1
    LMFAO, worked for me too after trying out everything mentioned here and didn't work! Thanks and +1!
    – Yustme
    Feb 22, 2014 at 12:56
  • Same issue here. The error appeared after a merge and would not go away until VS2012 was restarted.
    – StuartQ
    Jun 5, 2014 at 10:13
  • 1
    For me, what might have happened was the port was used by a second instance of Visual Studio that didn't have the project compiled. Apr 20, 2015 at 16:50
  • Worked for me as well. What a dump. Feb 20, 2018 at 16:41
  • 5 years later VS2017 and this is still the solution. :/
    – Sagiv b.g
    Jun 27, 2018 at 12:55
110

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

10
  • 8
    This was our issue as well. It had been previously set to something like Debug\x86\bin
    – t3rse
    Jan 10, 2012 at 16:25
  • 4
    HA! This is the second time in two years I've been to this article with this problem, first time it was the top answer, the second time it was this answer.
    – Ben Lesh
    Feb 1, 2012 at 21:36
  • 1
    Thanks! This bit me too. I had changed the platform to clear up some warnings, and the output path got changed without me knowing it.
    – camainc
    Apr 23, 2013 at 20:44
  • 6
    This was the right answer for me... Any idea about why Visual Stupido is behaving this way?
    – andreapier
    Jan 8, 2014 at 11:32
  • 1
    Yup, this was it. Changing to `bin` makes everything work as expected. @andreapier: Yes, VS2012 too seems to behave this stupid way. Somebody fix it ASAP! :) Jul 23, 2014 at 13:11
83

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.

4
  • Thanks, Vipul. I have just done the same thing and thought that I had lost a lot of work as a result. Just changing the namespace name has saved my bacon
    – xiecs
    Jun 21, 2011 at 12:18
  • 2
    I just did the same thing. I opened the Global.asax in a text editor and fix the namespace problem. Thanks May 11, 2013 at 8:10
  • 6
    I just did the same thing. Just to elaborate for anyone else : Originally I had a test project called "MvcApplication1" that was created automatically. I then did a global replace of the namespace "MvcApplication" to "MyTest". In the Global.asax in notepad I needed to then change to Inherits="MyTest.MvcApplication"
    – PabloInNZ
    Mar 13, 2014 at 22:42
  • If there was a way to give gold, I would
    – shanabus
    Mar 25, 2015 at 11:46
53

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.

1
  • This was winner for me, I'd dropped site from repo and set up iis, but never done a build in IIS Sep 11, 2014 at 9:27
32

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

3
  • 1
    This seems a bit odd when normally it's separated between the different build configurations. Apr 20, 2014 at 22:36
  • By default it is separated, but a lot of people change these to a single folder so that release and debug are in the same location for a different project that references the output (installers, etc).
    – StingyJack
    Apr 22, 2014 at 13:22
  • I wonder if this problem is peculiar to IIS Express. Anyhow, the reason I figured it out is because it's just screwed over one of our new starters: I'd changed bin to bin\Debug and bin\Release but the old files were still in my bin folder so I hadn't seen any problems. Of course, if you do a clean checkout and build these files don't exist for you so it blows up.
    – Bart Read
    Sep 12, 2017 at 14:33
17

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\"
4
  • 1
    Thank you so much for this, it fixed a problem I'd been having with breakpoints not setting!
    – Chris
    Dec 2, 2013 at 10:28
  • That was what worked for me. I discovered it by myself but thanks anyway.
    – Alexandre
    May 9, 2014 at 17:52
  • Holy crap! This saves a day.
    – ske
    Jul 4, 2019 at 1:01
  • Thanks. This was my issue. I set mine to bin\Debug and it should just be bin\
    – Jean Roux
    Aug 15, 2022 at 13:08
15

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

14

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.

3
  • 3
    I too had this problem. I wish Visual Studio would refactor the namespaces in the inherits attributes in the markup - as well as the classes. Sep 23, 2011 at 8:03
  • Same here. When renaming namespaces, make sure you shift-alt-F10, or right click to rename and it'll update all the instances for you.
    – Rob
    Jan 24, 2014 at 18:24
  • This worked for me, but it was hard to find where to implement the solution. I did a 'Find All' to access the Global.asax file because when you double-click on Global.asax in the Visual Studio editor, you get the Global.asax.cs file which is actually the code behind the .asax file. Note the .cs extension. So: CTRL-F and search for Global.asax (without .cs) and change the inheritance to match your namespace.
    – GerardV
    Feb 20, 2016 at 15:08
9

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 );
            }
        }
    }
1
  • Thanks @Farshid Saberi Aug 20, 2020 at 9:15
8
  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
6

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.

6

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.

1
  • Seems to be the likeliest cause for what happened to me. I had two instances of Visual Studio opened to different versions of my project (different directories). I closed one and rebuilt the other but, until I shut down all instances and rebuilt again, the error persisted. VS gets so easily confused.
    – Suncat2000
    Aug 20, 2021 at 13:46
4

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

4

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.

1
  • 1
    Thank you for the tip, the cause for me was that I recently relocated tfs. I needed to unmap the solution folder and map it again to make the app work!
    – adhie
    Jan 27, 2015 at 9:37
4

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.

3
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.
    – JLRishe
    Aug 18, 2014 at 9:16
  • @brasofilo I could have made the wrong call, but given the severe lack of information in the original question, it's highly likely that this is not the fix for OP's issue, and this answer is short enough that it could be added as a comment. On the other hand, the original question was posted a long time ago and there are a ton of "this is what worked for me" answers here, so it's a tough call. This question and its answers may be in need of some cleanup.
    – JLRishe
    Aug 18, 2014 at 9:26
  • @JLRishe, well, yeah, it's a mess of Q&A. This answer may even be duplicate of the second most upvoted, but I'm not sure. I'll flag the Q asking for a lock of 10rep minimum.
    – brasofilo
    Aug 18, 2014 at 9:31
4

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.

1
  • 2
    Changed it to release and it worked... changed it back to debug and it kept on working... thanks.
    – BLoB
    Apr 16, 2015 at 9:50
4

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

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

1
  • Didn't notice because the bleepity-bleep Error List said it was HAPPY!!!! Thank you.
    – CindyH
    Sep 15, 2016 at 21:33
3

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

1
  • The causes are indeed varied. I was changing a project's namespace globally. I was making a copy of an MVC project (not the right way to do that, but I just needed a fast dirty copy to play with) and the global.asax config file's Inherits attribute needed to be updated with the new namespace for the MvcApplication change (not the code behind cs.) That wasn't enough. Then I had to do a clean and rebuild to get the deployment to work then set the deploy to delete files on the server. The deployment was confused if an old dll got left behind. You simply can't just rename your project's namespace. Dec 8, 2020 at 18:54
2

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

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
  • I did a solution-level rebuild but I noticed my project's bin folder was empty. I did a build on just the project and suddenly I had a populated bin folder. I launched the project and it worked. Sep 7, 2016 at 15:26
2

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

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

2

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

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

1

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

1

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!

0
1

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

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

3
  • 2
    Wouldn't you want to ignore the bin folder, along with obj and other things that are built and not part of source code? Sep 7, 2016 at 15:24
  • Normally, yeah. But on this particular site, it was the only way to push items to the server. I probably should have made my answer more generic. Sep 7, 2016 at 23:47
  • I totally get the special circumstances stuff like that. Sep 8, 2016 at 0:06
1

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.

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