无法加载文件或程序集'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'



我的VisualStudio 2017 Wep API项目上有这个错误:

无法加载文件或程序集"系统运行时,版本=4.0.0.0, Culture=中性,PublicKeyToken=b03f5f7f11d50a3a' 或其之一 依赖。找到的程序集的清单定义没有 匹配程序集引用。(HRESULT的例外:0x80131040)

堆栈跟踪:

=== Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = .../WebApp/
LOG: Initial PrivatePath = ...bin
Calling assembly : System.Runtime.CompilerServices.Unsafe, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: ...web.config
LOG: Using host configuration file: ...IISExpressconfigaspnet.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.
LOG: Post-policy reference: System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/30ca8c3f/b4b96212/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/30ca8c3f/b4b96212/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///D:/DSTS/WF/WF1_0/WebApp/bin/System.Runtime.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

无法准确确定它何时发生,而是在更新到 Visual Studio(版本 15.3.2)或更新 wep API 包之后。

出现了其他一些问题,我已经解决了,但现在我陷入了这个错误。调用程序集System.Runtime.CompilerServices.Unsafe。 我的第一个猜测是降级这个包和依赖于这个的包,女巫我已经做了但没有成功。

我还尝试重新安装解决方案中的所有包,检查失败的程序集引用(有一些),检查重复的包版本。没有运气。

更新: 经过几次颠簸后,System.Runtime 现在存在于引用文件夹中,但标记为黄色(缺失)。我只是重新安装了"System.Runtime"软件包,因此我的解决方案已损坏或该软件包为错误。 目标框架是 4.7

就我而言,在使用Visual Studio 2017打开解决方案并收到此错误时,要解决此问题,我必须结合以下内容:

1) 在"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe.config">

查找任何出现的"..\..\MSBuild">并将其替换为"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild">

2)我注意到我的Microsoft.Build.Framework.dll在文件夹中丢失,进行了搜索并在"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\"。将其复制到"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE">

3)再次,在deven.exe.config中,更改了

codeBase version="15.1.0.0"href="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll">

到在AMD文件夹中找到的版本,就我而言:codeBase version="15.3.409.57025" href="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll">

我假设这与我安装了VS2017 Enterprise v15.3并且某些东西已损坏或错误有关。

在任何情况下,这都不是永久修复,但现在它对我来说效果很好,并且已经解锁了我的进度。如果我发现新的东西,会更新。

只是为了结束这个长期没有答案的问题,解决方案是在配置中设置绑定,所以当需要不同版本的 dll 时,.NET 框架知道允许使用不同的版本提供服务。

如果应用程序存在兼容版本的 dll 包,则此修复程序应该有效。

有关如何为任何 dll 设置绑定的说明如下:

https://stackoverflow.com/a/29497528/2700303

相关内容

最新更新