.net 解析器错误消息:无法加载类型“TestMvcApplication.MvcApplication”

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

Parser Error Message: Could not load type 'TestMvcApplication.MvcApplication'

.netasp.net-mvc

提问by Riaan Engelbrecht

I am getting the following error on one of our production servers. Not sure why it is working on the DEV server?

我在我们的一台生产服务器上收到以下错误。不知道为什么它在 DEV 服务器上工作?

Parser ErrorDescription: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'TestMvcApplication.MvcApplication'.

Source Error:

Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="TestMvcApplication.MvcApplication" Language="C#" %>

Source File: /global.asax Line: 1

解析器错误说明:解析服务此请求所需的资源期间发生错误。请查看以下特定解析错误详细信息并适当修改您的源文件。

解析器错误消息:无法加载类型“TestMvcApplication.MvcApplication”。

源错误

第 1 行:<%@ Application Codebehind="Global.asax.cs" Inherits="TestMvcApplication.MvcApplication" Language="C#" %>

源文件:/global.asax 行:1

Not sure if anybody came across this error before and how it was solved, but I have reached the end. Any help would be appreciated.

不确定之前是否有人遇到过这个错误以及它是如何解决的,但我已经走到了尽头。任何帮助,将不胜感激。

I also need to mention that this is the published code, so all is compiled. Can there be something wrong with my compiler settings?

还需要提一下,这是公开的代码,所以都是编译好的。我的编译器设置有问题吗?

回答by Brian Leeming

None of the other answers worked for me. I fixed my error by changing the web project's output path. I had had it set to bin\debug but the web project doesn't work unless the output path is set to simply "bin"

其他答案都不适合我。我通过更改 Web 项目的输出路径修复了我的错误。我已将其设置为 bin\debug,但除非将输出路径设置为简单的“bin”,否则 Web 项目不起作用

回答by Andy Copley

I've had this a couple of times. It's especially frustrating as it's right off the bat, and the error message holds no clue as to what might be the issue.

我有过几次这样的经历。它特别令人沮丧,因为它立即生效,并且错误消息不知道可能是什么问题。

To fix this, right click your project title, in this case "TestMvcApplication" and click build.

要解决此问题,请右键单击您的项目标题,在本例中为“TestMvcApplication”,然后单击build

This forces the code to compile before you run it. Don't ask me why, but this has been the solution 100% of the time for me.

这会强制代码在运行之前编译。不要问我为什么,但这对我来说是 100% 的解决方案。

回答by DamoDBear

I have found that when you are forced to use the Configuration Manager to run under x86 or anything other than the standard project "out of the box" settings, the IDE creates a bunch of sub directories under the bin folder for the web project.

我发现当您被迫使用配置管理器在 x86 或标准项目“开箱即用”设置以外的任何设置下运行时,IDE 会在 web 项目的 bin 文件夹下创建一堆子目录。

Once this starts happening, if the Cassini server is running, then the project does not serve properly.

一旦发生这种情况,如果 Cassini 服务器正在运行,则该项目将无法正常运行。

I fixed it by going into the Web Project properties -> Build settings and changing the Output Path to be bin\

我通过进入 Web 项目属性 -> 构建设置并将输出路径更改为 bin\

Then rebuild and all works as it should.

然后重建,一切正常。

回答by Carl Wright

I had what looked like the same error. I tried many suggestions from many pages only to find out the problem was that I had the website set to the wrong version of .Net

我遇到了同样的错误。我尝试了许多页面的许多建议,结果发现问题是我将网站设置为错误的 .Net 版本

No matter how many re-compiles or people saying 'configuration problem', nobody made the point that the .net version needed to be checked.

无论有多少重新编译或有人说“配置问题”,都没有人指出需要检查 .net 版本。

回答by teedyay

I had the same problem: mine was because the web project had a platform target of x86. I was running on a 64-bit machine; other projects in the solution were set to 64-bit.

我有同样的问题:我的问题是因为 web 项目的平台目标是 x86。我在 64 位机器上运行;解决方案中的其他项目设置为 64 位。

To check your settings, right click the project and choose Properties. On the Build tab, check the value of "Platform Target".

要检查您的设置,请右键单击该项目并选择“属性”。在 Build 选项卡上,检查“Platform Target”的值。

Also check your solution's build configuration (Build menu > Configuration Manager) to check all your projects are being built to the same platform.

还要检查您的解决方案的构建配置(构建菜单 > 配置管理器)以检查您的所有项目是否构建到同一平台。

In both cases, make sure you check the settings both for debug and release mode - otherwise you'll get it working on your machine but not when you deploy it!

在这两种情况下,请确保检查调试和发布模式的设置 - 否则您将使其在您的机器上运行,但在部署时却无法运行!

回答by Manish Jain

I tried all above solutions but no luck. Adding line <add assembly="*" />to web.config fixed it for me. (You can also add to machine.config or root web.config file of the appropriate .NET framework version, I didn't try it) Thanks to MS Support for solution.

我尝试了上述所有解决方案,但没有运气。添加行<add assembly="*" />到 web.config 为我修复了它。(也可以添加到machine.config 或者.NET 框架版本的root web.config 文件中,我没试过)感谢MS 支持解决。

回答by Riaan Engelbrecht

After a long hard look I came accross the real issue here.

经过长时间的努力,我在这里遇到了真正的问题。

The assemblies were corrupted by the FTP client I used to upload the files to a hosted environmet.

我用来将文件上传到托管环境的 FTP 客户端损坏了程序集。

I changed my FTP client and all is working as intended.

我更改了我的 FTP 客户端,一切都按预期工作。

回答by Paulo

IT happens with me when I rename my project/solution. Go to the folder of project in windows explorer (get out of VS). Find and open the file Global (maybe you'll find 2 files, open that dont have ".asax.cs" extension), and edit the line of error with correct path. Good luck!

当我重命名我的项目/解决方案时,它会发生在我身上。转到windows资源管理器中的项目文件夹(退出VS)。找到并打开文件 Global(也许你会找到 2 个文件,打开没有“.asax.cs”扩展名的文件),并用正确的路径编辑错误行。祝你好运!

回答by Jaco Pretorius

I experienced the exact same problem a couple of days ago - as far as I can tell it was an issue with a 64-bit IIS running a 32-bit web application. We changed our production server to 32-bit and this issue disappeared.

几天前我遇到了完全相同的问题 - 据我所知,这是运行 32 位 Web 应用程序的 64 位 IIS 的问题。我们将生产服务器更改为 32 位,这个问题就消失了。

回答by Ace Hyzer

Make sure your default namespace in the web project properties is the same as the namespace in the Global.asax.cs. I had modified the default namespace to make it a subnamespace, changing it back fixed this issue for me.

确保 Web 项目属性中的默认命名空间与 Global.asax.cs 中的命名空间相同。我修改了默认命名空间以使其成为子命名空间,将其改回来为我解决了这个问题。