[asp.net-mvc] Error: «Could not load type MvcApplication»

I am getting the error

Could not load type MvcApplication

when I try to run my website.

How to correct it?

This question is related to asp.net-mvc

The answer is


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.


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


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.


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\"

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.


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


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


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.


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


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. Right click on the project within the solution that is failing.
  2. Unload Project
  3. Reload Project
  4. Build Project
  5. Re-build Solution

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.


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


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.


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.


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.


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
}

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 );
            }
        }
    }

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


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.


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.


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.


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.


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.


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.


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


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.


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


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.


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


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


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.


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


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


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!


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\


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.


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


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.


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


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


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