C# ASP.Net MVC 执行时“无法加载类型”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/841311/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:44:48  来源:igfitidea点击:

ASP.Net MVC "Could Not Load Type" when executing

c#asp.netasp.net-mvc

提问by Goober

I have a very simple ASP.Net MVC Application that I have produced from an online tutorial. I've followed it exactly, step by step and have tried multiple times but keep getting the same error when I execute the code.

我有一个非常简单的 ASP.Net MVC 应用程序,它是从在线教程中生成的。我已经完全按照它一步一步地进行了并尝试了多次,但是在执行代码时总是出现相同的错误。

The program just displays an index page which lists a series of data from an sql server database using linq to sql.

该程序仅显示一个索引页面,其中列出了使用 linq to sql 的 sql server 数据库中的一系列数据。

This is the error:

这是错误:

Could not load type 'MvcApplication1.Views.Home.Index'.

无法加载类型“MvcApplication1.Views.Home.Index”。

Any ideas what the problem could be?

任何想法可能是什么问题?

采纳答案by Jon Davis

Possible answer here:

可能的答案在这里:

http://www.jondavis.net/techblog/post/2009/04/29/Set-Up-IIS-For-An-MVC-App-When-All-Else-Fails-Check-View-Config.aspx

http://www.jondavis.net/techblog/post/2009/04/29/Set-Up-IIS-For-An-MVC-App-When-All-Else-Fails-Check-View-Config.aspx

Basically, add the Views directory's web.config to your target Views directory. Although, it doesn't sound like you're using a strongly typed view, or aren't deploying your code.

基本上,将 Views 目录的 web.config 添加到您的目标 Views 目录。虽然,这听起来不像您在使用强类型视图,或者没有部署您的代码。

Also, I have seen this problem also appear if the compile settings are removed from web.config. In an ASP.NET MVC project created in Visual Studio 2008, those settings are included in web.config, and they should remain or else this error will occur.

另外,我发现如果从 web.config 中删除编译设置,也会出现此问题。在 Visual Studio 2008 中创建的 ASP.NET MVC 项目中,这些设置包含在 web.config 中,它们应该保留,否则会发生此错误。

回答by GuyIncognito

That seems like a pretty ambiguous error to me. What hints does your Stack Trace give you? What framework method throws the exception?

这对我来说似乎是一个非常模棱两可的错误。你的 Stack Trace 给你什么提示?什么框架方法抛出异常?

回答by Adam

Are you running the current version of MVC? There was a big update in the Release Candidate that removed the code-behinds on views.

您是否正在运行当前版本的 MVC?Release Candidate 中有一个重大更新,删除了视图中的代码隐藏。

I ran into the same issue. Uninstalling MVC, then reinstalling fixed the problem for me. This can be done in Control Panel --> Add/Remove Programs.

我遇到了同样的问题。卸载 MVC,然后重新安装为我解决了问题。这可以在控制面板 --> 添加/删除程序中完成。

Hope this helps, Adam

希望这会有所帮助,亚当

回答by Kalid

I had a similar "Could Not Load Type" problem with ASP.NET MVC in my Global.asax. The fix was to ensure the case of the inherits property was the same as the class it was referencing -- I didn't realize it was case sensitive!

我的 Global.asax 中的 ASP.NET MVC 有一个类似的“无法加载类型”问题。修复方法是确保继承属性的大小写与它引用的类相同——我没有意识到它区分大小写!