I am getting the error
Could not load type MvcApplication
when I try to run my website.
How to correct it?
I am getting the error
Could not load type MvcApplication
when I try to run my website.
How to correct it?
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.
[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.
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 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...
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
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...
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.
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.
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.