我在一个MVC3项目上工作,收到以下错误:

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

源错误:

第1行:<%@ Application Codebehind="Global.asax.cs" Inherits="GodsCreationTaxidermy.Core. core . "MvcApplication" Language=" c# " %>

我得到的错误是无法加载GodsCreationTaxidermy.Core.MvcApplication,但在这个屏幕截图中,核心部分没有显示在错误中:

有人对这个错误有什么想法或解决方案吗?


当前回答

如果你在同一个解决方案中运行Web和WebApi,如果你不小心忘记将VS解决方案设置为“多个启动项目”,也会发生这种情况。

您可以通过右键单击解决方案资源管理器中的解决方案并选择“属性”来检查这一点。然后寻找“创业项目”。

其他回答

尝试修改全局变量。Asax文件(简单添加一个空格的地方),并重新运行。这将迫使内置的web服务器刷新和重新编译全局。asax文件。

也做一个清理和重建-应该修复问题

如果在全局变量之后更改名称空间信息(项目或类级别),有时会发生这种情况。生成Asax。

右键单击全局。asax文件,选择“打开”,然后选择“XML(文本)编辑器与编码”(其他编辑器也可以工作,但这是我使用的)。

然后编辑XML指令中的“Inherits”部分

<%MvcApplication" Language " ="C " %>)

以便它与应用程序类的实际全名相匹配。就是这样。

另一种选择是从Global.asax.cs中复制所有代码,然后删除并创建另一个Global。asax文件(然后将代码复制回Global.asax.cs)。

我今天遇到了这个问题,我花了一段时间才找到原因。

基本上,我的VS2015主项目包括一个使用更高版本的. net Framework构建的子项目。

奇怪的是,当你遇到这个问题时,VS2015会很高兴地报告解决方案已经构建好了,但当你尝试运行网站时,它只是给你一个误导性的错误,表明你的Global.asax.cs文件是错误的。

因此,如果您看到这个错误,并且清理/重建不起作用,打开项目的引用树,并检查感叹号。

同样,检查你的输出窗口是否有这样的消息:

The primary reference "C:\Projects\Business Objects 4\bin\Release\BusinessObjects.dll" 
could not be resolved because it was built against 
the ".NETFramework,Version=v4.5" framework. 
This is a higher version than the currently targeted framework
".NETFramework,Version=v4.0".

当然,解决方案是右键单击您的主项目,选择顶部选项卡“Application”,并将目标框架版本更改为与您的子项目匹配的更高版本。

Visual Studio 2015会让你完全构建和运行包含这个问题的解决方案,这很令人恼火。这是自找麻烦!

有两种方法:

配置管理器将dll构建显示为'64'和'any cpu'构建的混合。 将它们都放在同一个构建中可以解决这个问题。 在分支之间切换时,IIS快速路径有时不会更新。右键单击任务栏中的“IIS Express”>显示所有应用程序,并验证路径是否指向正确的分支。

TL;DR:对我来说,在尝试了3天我能在这里找到的所有其他答案之后,最终的解决方案是在我的IIS应用程序池高级设置中将启用32位应用程序设置为True,然后重新创建临时ASP。并为我的IIS_IUSRS组增加“修改”和“写入”权限。

我尝试的步骤:

Completely clean and rebuild solution. Shut down and restart Visual Studio. Delete Temporary ASP.NET Files directories (C:\Windows\Microsoft.NET\Framework*). This is where my problems really started: I deleted too much. Reboot development machine. Remove .vs folder and rebuild solution. Recreate C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files. My projects are 64-bit applications, even though build platform is AnyCPU. Verify output directory was set to bin/ on web projects. Wipe out and check out a clean copy of my version control branch. Wipe out and clone a fresh copy of my version control repository. Run Windows update to latest versions of .NET Frameworks. Repair, uninstall, and reinstall .NET Frameworks 3.5 and 4.8. Uninstall and reinstall Visual Studio 2019 Professional. Uninstall and reinstall the Internet Information Services feature in Windows. Downgrade ASP.NET NuGet package and rebuild solution (issued reference errors due to changes in assemblies). Upgrade ASP.NET back to what my projects were using and rebuild solution. Recreate IIS virtual directory through web project's Web properties. Created "empty" Global.asax files. Restore my files after no change. Replace Codebehind="Global.asax.cs" with Codefile="Global.asax.cs". This started showing me load errors for references to assemblies that actually existed in the system. Enable 32-bit applications in IIS application pool. This started displaying an access error to a 32-bit temporary directory. Restore permissions to all Temporary ASP.NET Files directories (add all but Full Control). This finally got my web application working again.

我能够从网上找到的无数答案中拼凑出足够的信息。在搜索iis找不到引用的。net dll后找到了这个答案,我尝试了最后的几个步骤,让我再次工作,在我的第四天开始与这个令人难以置信的模糊问题作斗争。

如果有办法诊断出为什么全球。asax无法加载,而不是太通用的无法加载类型错误,没有详细信息。

这个故事的寓意:当清理临时ASP。NET Files目录,删除目录的内容,而不是目录本身。否则,可能会导致权限丢失。