asp.net-mvc 错误:?无法加载类型 MvcApplication?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1120329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: ?Could not load type MvcApplication?
提问by Gil
I am getting the error
我收到错误
Could not load type MvcApplication
无法加载类型 MvcApplication
when I try to run my website.
当我尝试运行我的网站时。
How to correct it?
如何纠正?
回答by gurrawar
As dumb as it might sound, tried everything and it did not work and finally restarted VS2012 to see it working again.
尽管听起来很愚蠢,但尝试了所有方法但它不起作用,最后重新启动 VS2012 以查看它再次运行。
回答by bob new
-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.
- 对我来说,修复是在构建选项卡中更改输出路径。我将输出路径更改为bin\并且错误消失了。
-Another fix could be that you have the wrong start up project set.
- 另一个解决方法可能是您设置了错误的启动项目。
回答by Vipul
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 Testshould 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.
我遇到了同样的错误,尽管做了这里和其他地方提到的所有事情,但没有任何效果。结果是我从项目的先前版本中复制了 global.asax.cs 的源代码,该版本具有不同的名称。所以namespace Test应该是namespace Test.WebUI。当然是一个愚蠢的错误,写这个有点尴尬!但是写下来是希望其他人的类似错误可能会导致他也检查这个微不足道的方面。
回答by mark vanzuela
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.
如果您使用的是本地 IIS,请尝试在 IIS 管理器中删除网站注册,然后手动重新创建。
回答by StingyHyman
[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.
如果您收到此错误:“无法加载类型 MvcApplication”,请查看项目的输出路径并确保将其设置为“bin\”。问题在于,如果文件不在默认位置,AspNetCompiler 将无法找到这些文件。
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.
更改输出文件夹的另一个副作用是您将无法调试代码,并且会出现一条消息,指出无法找到程序集信息。
回答by A_B
I had the same issue and solved it with below steps
我遇到了同样的问题并通过以下步骤解决了它
- Go to project properties
- On the "Build' tab, set output path to "bin\"
- 转到项目属性
- 在“构建”选项卡上,将输出路径设置为“bin\”
回答by Pomster
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.
我尝试重新启动VS。我尝试将输出路径设置为 \bin。我检查了我的名字空间。
But what worked for me was rebuilding the solution.
但对我有用的是重建解决方案。
Rebuild Solution!!!
重建解决方案!!!
回答by mkaj
My solution: Because I created the problem! I had changed the namespace in Global.asax.cs
我的解决方案:因为我创造了问题!我已经更改了 Global.asax.cs 中的命名空间
You also need to change the Inherits attribute value in the Global.asax.
您还需要更改 Global.asax 中的 Inherits 属性值。
回答by Farshid Saberi
Check code behind information, provided in global.asax. They should correctly point to the class in its code behind.
检查 global.asax 中提供的信息背后的代码。他们应该正确地指向后面代码中的类。
sample global.asax:
示例 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 );
}
}
}
回答by JoshYates1980
- Right clickon the project within the solution that is failing.
- Unload Project
- Reload Project
- Build Project
- Re-build Solution
- 右键单击解决方案中失败的项目。
- 卸载项目
- 重新加载项目
- 构建项目
- 重建解决方案

