251

I am getting the error

Could not load type MvcApplication

when I try to run my website.

How to correct it?

Gil
  • 1,037
  • 4
  • 12
  • 14
  • 38
    I got this error randomly one day on our build server. doing a manual rebuild resolved it. – Zack Aug 14 '09 at 21:27
  • 1
    The Output path is set in the project properties on the build tab – Silas Davis May 02 '12 at 12:04
  • 9
    delete global.asax file and add a new one, and you will be alright. – DotNetGeek Jul 08 '13 at 07:51
  • possible duplicate of http://stackoverflow.com/questions/1598829/parser-error-message-could-not-load-type-testmvcapplication-mvcapplication – Brian Leeming Feb 12 '14 at 18:25
  • 4
    It turns out that the new project was not selected in the active configuration for build. – JGeerWM Jan 28 '15 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 – David Bridge Jul 22 '15 at 09:29
  • Also met this error when I tried to rename some class & reference. I go on deleting bin, obj folders then rebuild, but still does not work. However, restarting visual studio solve it – Hoàng Long Oct 30 '15 at 06:42
  • 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. – MrBoJangles Sep 07 '16 at 15:30
  • This happened to me when deploying a previously working application. Something in IIS (7) got into a bad state; resetting IIS fixed the problem. – BurnsBA Sep 21 '16 at 12:34
  • I had gotten this error after adding another publish configuration. I could not figure out what caused it, but shelving the changes I made seemed to have solved it. Maybe someone can tell me why. – BoldAsLove Sep 08 '17 at 19:19

43 Answers43

119

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

gurrawar
  • 363
  • 2
  • 8
  • 17
109

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

RayLoveless
  • 19,880
  • 21
  • 76
  • 94
bob new
  • 1
  • 1
  • 2
  • 2
  • 8
    This was our issue as well. It had been previously set to something like Debug\x86\bin – t3rse Jan 10 '12 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 01 '12 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 '13 at 20:44
  • This was our issue as well, for the Web project. We had changed the debug configuration to use x86, and VS2010 automatically changed the output path on all of the projects to bin\x86\Debug\. Changing only the web project's path back to bin\ fixed it for us. – Alan Jun 17 '13 at 22:02
  • 6
    This was the right answer for me... Any idea about why Visual Stupido is behaving this way? – andreapier Jan 08 '14 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! :) – now he who must not be named. Jul 23 '14 at 13:11
  • 1
    Worked for me too. Does anyone know why this is problematic? – Pavle Gartner Mar 11 '16 at 11:04
  • That was it! Thanks a lot. – GETah May 19 '16 at 07:46
  • It's even the cause of not being able to debug at all (all breakpoints were not working anymore even if the app was working)... resetting all to bin fixed the problems... – Micaël Félix Mar 16 '17 at 17:03
  • wow so surprised this works. Second magical answer for me today, next to [this one](https://stackoverflow.com/questions/13548851/msbuild-usingtask-resolve-references) – stuzor Nov 16 '18 at 17:20
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.

Vipul
  • 18
  • 2
  • 5
  • 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 '11 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 – Kayvan Karim May 11 '13 at 08: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 '14 at 22:42
  • If there was a way to give gold, I would – shanabus Mar 25 '15 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.

Peter Morris
  • 20,174
  • 9
  • 81
  • 146
mark vanzuela
  • 1,373
  • 4
  • 23
  • 37
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.

StingyJack
  • 19,041
  • 10
  • 63
  • 122
  • 1
    This seems a bit odd when normally it's separated between the different build configurations. – nicodemus13 Apr 20 '14 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 '14 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 '17 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\"
A_B
  • 51
  • 1
  • 9
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!!!

Pomster
  • 14,567
  • 55
  • 128
  • 204
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.

mkaj
  • 3,421
  • 1
  • 31
  • 23
  • 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. – csharpforevermore Sep 23 '11 at 08: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 '14 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 '16 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 );
            }
        }
    }
Farshid Saberi
  • 917
  • 13
  • 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
JoshYates1980
  • 3,476
  • 2
  • 36
  • 57
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.

StingyJack
  • 19,041
  • 10
  • 63
  • 122
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.

Steve Dunn
  • 21,044
  • 11
  • 62
  • 87
  • 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 '21 at 13:46
4

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

Malcolm Swaine
  • 109
  • 1
  • 3
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.

Will Newton
  • 1,583
  • 13
  • 10
  • 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 '15 at 09: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.

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
zaydev
  • 1
  • 1
  • 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](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – JLRishe Aug 18 '14 at 09: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 '14 at 09: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 '14 at 09: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.

Amanda
  • 159
  • 1
  • 3
  • 16
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...

junta
  • 201
  • 3
  • 13
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

Tawab Wakil
  • 1,737
  • 18
  • 33
TonyG
  • 1,432
  • 12
  • 31
  • 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. – Hunter-Orionnoir Dec 08 '20 at 18:54
3

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

Gautam Jain
  • 6,789
  • 10
  • 48
  • 67
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\

Johnie Karr
  • 2,744
  • 2
  • 35
  • 44
  • 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. – MrBoJangles Sep 07 '16 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.

mmmMAC
  • 1
  • 1
  • 1
2

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

IndieTech Solutions
  • 2,527
  • 1
  • 21
  • 36
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.

Rob
  • 2,080
  • 4
  • 28
  • 48
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...

Sam
  • 1,725
  • 1
  • 17
  • 28
1

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

rocktheartsm4l
  • 2,129
  • 23
  • 38
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!

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.

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
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.

Brent Waggoner
  • 548
  • 3
  • 14
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.

webternals
  • 161
  • 7
1

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

Awk
  • 1
  • 1
1

Could not load type MVCApplication1.MVCApplication

Problem: Web.Config might be corrupted because of some updates in the machine. When I compared the web.config with server web.config then I realized that all the basic configuration were missing like build providers, modules, handlers, namespaces etc.

Resolution: Replace the web.config from the below location with web.config from server from same location (application is running fine in server). C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config

I have spent more than 10 days, hence I thought it might be helpful for someone.

TTY
  • 21
  • 5
  • This massively helped thank you. I was missing some key assembly references as i was using to prevent inheritance on a parent application. Removing the clear fixed the problem. – Gary Henshall Aug 19 '21 at 10:19
0

I had tested every one of these things and none worked. I then remembered I was running the site through my local instance of IIS and had moved the directory where I was compiling the code to. In other words, my IIS site was setup to look at the old directory which had an issue. Going in IIS and changing the root of the site to my new directory obviously fixed the problem.

sewershingle
  • 149
  • 1
  • 5
0

My problem was that I hadn't built the project yet (oops). Don't know if this really helps anyone, but just make sure you build everything before clicking links.

rookie1024
  • 612
  • 7
  • 18
0

I tried a lot of suggestions but what worked for me was to use the 'publish' functionality (in the Build tab) of Visual studio. I simply used the FTP deployment choice to send the bits to my server with my FTP creds. Then I point IIS at the directory. Of course check your app pool for the correct framework.

pat capozzi
  • 1,412
  • 1
  • 20
  • 16
0

I just had this problem with an ASP.NET MVC Web API project and none of the solutions did the trick.

I managed to solve the problem by rebooting the machine. I did an upgrade to Visual Studio 2013, which didn't require reboot, but that was probably causing the problem.

Dante
  • 3,833
  • 4
  • 38
  • 55
0

my problem was that I had 2 projects running on same port. Solution was to change ports and recreate a new virtual directory for the new project

jordan koskei
  • 2,749
  • 1
  • 15
  • 12
0

Tried everything else then I googled the error I was getting about not being able to find nuget.exe... I thought, well I dont really need that... Turns out I did. Solution I found: Right click on the Solution and click Enable NuGet Package Restore

Adam Pine
  • 387
  • 2
  • 7
0

In my case issue was I renamed class Global to MvcApplication. When renaming it has to be changed on all places, otherwise app is looking for Global class in given namespace.

Qerts
  • 935
  • 1
  • 15
  • 29
0

I was working with Azure Mobile App and that problem was when I added MVC Controller. And if you delete all files from Team Explorer (Undo), you will need to delete bin, obj and Global.asax.cs from Solution folder

Vlad
  • 852
  • 10
  • 23
0

This happened to me because I added Global.asax.cs (C# file) to a VB.net project so the file didn't get compiled and I had to use a .vb version of the file for it to work and get compiled.

Warix3
  • 99
  • 1
  • 11
0

In my case the problem was that I changed the workspace name and the value apparently is case sensitive.

Mike
  • 173
  • 2
  • 5
0

You have to check the action method, whether there is one or more methods when calling the method that overloads argumens or invalid argument enter image description here

public string test(string a, string b){

}

public ActionResult x(){
     test(a) //test is need two arguments
}
AgungCode.Com
  • 677
  • 6
  • 9
  • Perhaps this helped you, but you didn't offer any explanation of why any action method would cause this problem or how you determined that would get your application to run again. Otherwise, there is no connection to the problem or its resolution here. – Suncat2000 Aug 20 '21 at 13:42
0

I had the same issue and what I did is to close my application and clean my temporary files and again rebuild the application. it worked for me :)

arqum farooq
  • 23
  • 1
  • 5