我得到了错误

无法加载类型mvcapapplication

当我试图运行我的网站时。

如何纠正?


当前回答

确保global.asax.cs中的命名空间与你的webapp的命名空间匹配

其他回答

我得到了同样的错误,尽管做了这里提到的所有事情,但没有任何工作。原来我从以前版本的项目中复制了global.asax.cs的源代码,该版本的名称不同。因此名称空间Test应该是名称空间Test. web。这当然是一个愚蠢的错误,我有点不好意思写这个!但写这封信的目的是希望其他人的类似错误也能让他检查一下这个微不足道的方面。

对我有效的是重新启动Visual Studio。

我尝试手动重建,执行清理和重建,并删除bin文件夹,所有这些都没有工作。我的输出路径已经设置为bin\

啊,这太烦人了。

在断电后得到这个错误,我回到了我的项目。

我试着重启VS。 我试着将输出路径设置为\bin。 我检查了我的名称空间。

但对我来说有效的是重新构建解决方案。

重建方案! !

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.

这与其他答案相关——如果你的web项目的程序集不可用,你会得到这个错误。但这可能是一个常见的场景,特别是因为您实际上编译了您的解决方案——项目只是没有得到构建。

检查global.asax中提供的信息背后的代码。它们应该正确地指向后面代码中的类。

示例global.asax:

<%@ Application Codebehind="Global.asax.cs" Inherits="MyApplicationNamespace.MyMvcApplication" Language="C#" %>

背后的示例代码:

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