Error: «Could not load type MvcApplication»

后端 未结 30 1464
心在旅途
心在旅途 2020-11-28 02:18

I am getting the error

Could not load type MvcApplication

when I try to run my website.

How to correct it?

相关标签:
30条回答
  • 2020-11-28 02:47

    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 );
                }
            }
        }
    
    0 讨论(0)
  • 2020-11-28 02:47

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

    0 讨论(0)
  • 2020-11-28 02:48

    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

    0 讨论(0)
  • 2020-11-28 02:49
    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
    0 讨论(0)
  • 2020-11-28 02:49

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

    0 讨论(0)
  • 2020-11-28 02:51

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

    0 讨论(0)
提交回复
热议问题