在使用 VS config 添加新配置后尝试调用
GetDatabase
类的 MongoClient
方法时,出现以下异常。经理:
Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
我安装了最新的 System.Buffer nuget 包 v4.5.1,在 app.config 中创建了 dependentAssembly,并在 .csproj 文件中创建了 Reference,但我仍然遇到同样的问题。由于某种原因,它尝试使用 v4.0.2 引用 System.Buffer。有没有人遇到过类似的错误,你是如何解决的?
无法加载文件或程序集“System.Buffers,版本=4.0.2.0…”
解决方案
1)使用CMD(以管理员身份运行)并输入
cd xxxx(xxxx\packages\System.Buffers.4.5.1\lib\netstandard2.0))
奔跑
gacutil /i System.Buffers.dll
然后,完成后,请运行
update-package -reinstall
下的package manager console
重新安装软件包。
2)你可以尝试在csproj文件中将
Version=4.0.2.0
更改为Version=4.0.3.0
。
此外,还有一个类似的问题可以参考一下。
就我而言,我必须在已在 Azure 应用服务中发布的 web.config 中添加程序集引用,位于
<configuration></configuration>
标签内:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
我在将
Azure.Storage.Blobs
包添加到类库时遇到了这个问题,我试图在其中创建 blob 上传器客户端。当我添加包时,它创建了一个具有正确绑定重定向的 app.config
:
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
然而,问题是这个绑定重定向需要存在于应用程序的
app.config
中,而不是类库中:类库可以有 App.config 文件吗?
所以,添加绑定重定向是解决这个问题的正确方法。只需确保在调用 Web/控制台/等应用程序中指定绑定重定向即可。
最简单的方法是使用 Nuget 包管理器,将 system.buffers 降级到任意较低版本,然后再次升级到最新版本。
就我而言,答案是依赖项位于 DLL 中,但引用 DLL 的 EXE 还需要在 app.config 的运行时部分包含程序集绑定:
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
重建应用程序然后为我解决了问题。 VS2017 C# Winforms 应用程序 .NET 框架 4.6.1.
另一个解决方案:只需删除生成异常的项目的
Web.config
文件中对程序集的引用即可。
参考文献可以如下所示:
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
</dependentAssembly>
我遇到了类似的问题,尝试了上述所有步骤。最后,另一个项目拥有同一库的旧版本。解决方案中的项目太多,其他参考已滚动到视图之外。
只需安装 NuGet Package 4.4.0 并将依赖的程序集 (System.Buffers) 部署到 Gac。
我们在建议的解决方案中遇到了问题。 我们的软件(32 位 .NET Framework)附带 System.Buffers,我们在解决它时没有遇到任何问题。我认为这实际上是解决问题的正确方法,但当然需要再次分发/安装软件。
但是,我们现在在 System.Buffers.dll (netstandard1.1) 位于 GAC 中的计算机上遇到软件崩溃的情况。由于 GAC 是首选(here)并且加载了 GAC dll 而不是我们提供的 dll,因此我们随后在解决 System.Threading.dll 和 System.Runtime.dll 时遇到了问题(两者都在由 .NET Framework 安装的 GAC 中) .
从 GAC 中删除 dll 解决了我们的问题,但显然可能会破坏将 dll 放入 GAC 的人。