[英]Could not load file or assembly Microsoft.CodeAnalysis
I have a webproject I am trying to host, but when the server tries to compile it, I get the following error:我有一个要托管的 web 项目,但是当服务器尝试编译它时,出现以下错误:
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
未处理的异常:System.IO.FileLoadException:无法加载文件或程序集“Microsoft.CodeAnalysis,版本=1.1.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference.
定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
(来自 HRESULT 的异常:0x80131040)---> System.IO.FileLoadException:无法加载文件或程序集“Microsoft.CodeAnalysis,版本=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference.
定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040)
(来自 HRESULT 的异常:0x80131040)
--- End of inner exception stack trace --- at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args)--- 内部异常堆栈跟踪结束 --- 在 Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args)
So the server has an older version of CodeAnalysis than my project.所以服务器的 CodeAnalysis 版本比我的项目旧。 So lets try a binding redirect!
所以让我们尝试绑定重定向!
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.9.9.9" newVersion="1.0.0.0" />
</dependentAssembly>
Sadly, I still get the same error.可悲的是,我仍然遇到同样的错误。 What am I doing wrong?
我究竟做错了什么?
I figured this out myself.这是我自己想出来的。 To anyone reading this, the problem was that the Nuget package
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
(which also contains the CodeAnalysis package) was the wrong version.对于阅读本文的任何人来说,问题在于 Nuget 包
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
(也包含 CodeAnalysis 包)是错误的版本。 I created a new webproject, updated the offending Nuget package right away, and the problem was solved.我新建了一个webproject,马上更新了有问题的Nuget包,问题解决了。
I resolved this issue but ensuring that the version numbers of the assemblies in my web.config were correct.我解决了这个问题,但确保我的 web.config 中程序集的版本号是正确的。
Edit:编辑:
I hit this problem as well and some may wonder how the Web.Config can become incorrect.我也遇到了这个问题,有些人可能想知道 Web.Config 怎么会变得不正确。 In my case I am using Web.Config Transforms so the Web.Config file gets overwritten:
在我的情况下,我使用 Web.Config 转换,因此 Web.Config 文件被覆盖:
Changing the version number in Web.Configs compiler (in the Web.Template.Config) to the number matches the NuGet version does solve the issue:将 Web.Configs 编译器(在 Web.Template.Config 中)中的版本号更改为与 NuGet 版本匹配的数字确实可以解决问题:
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0
Other possible fix (at least for Visual Studio 2015):其他可能的修复(至少对于 Visual Studio 2015):
Get the latest Visual Studio update.获取最新的 Visual Studio 更新。
You can check for updates by going to Tools/Extensions and Updates/Updates
您可以通过转到
Tools/Extensions and Updates/Updates
来检查Tools/Extensions and Updates/Updates
Same as this Q/A: Visual Studio 2015: Quick Actions no longer working, error: Could not load file or assembly Microsoft.CodeAnalysis与此问答相同: Visual Studio 2015:快速操作不再有效,错误:无法加载文件或程序集 Microsoft.CodeAnalysis
我今天在进行 Umbraco v7.13.0 升级时遇到了这个问题,只需更新以下软件包即可解决我的问题,这显然是Umbraco upgrades 之类的常见问题。
Update-Package -Reinstall Microsoft.CodeAnalysis.CSharp
If none of mentioned options work, please go for this answer.如果上述选项均无效,请选择此答案。 Basically, you are registering that Microsoft.CodeAnalysis.dll to GAC
基本上,您正在将该Microsoft.CodeAnalysis.dll注册到 GAC
Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependenc 无法加载文件或程序集“Microsoft.CodeAnalysis,版本= 1.3.1.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一
右键单击您的项目 >> 管理解决方案的 Nuget 包管理器 >> 点击更新 >> 更新您的“Microsoft.CodeDom.Providers.DotNetCompilerPlatform” >> 然后再次运行您的项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.