【发布时间】:2019-02-01 19:15:04
【问题描述】:
我的处境让人想起“DLL 地狱”。我想我正在使用一堆可能会混淆情况的 nuget 包。
抱怨在运行时找不到 System.Net.Http 4.0.0.0
System.IO.FileLoadException:无法加载文件或程序集“System.Net.Http,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)
但是,我的 app.config 中有以下内容:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
我希望任何加载 4.0.0.0 的尝试都会加载 4.1.0.0,但事实并非如此。我不知道为什么。
这也可能与旧的单元测试中发生有关。 app.config 在单元测试项目中。
附:我在这个一般领域看到了其他问题,但他们没有回答我的问题,因为我在这里使用 100% C# 代码。
【问题讨论】:
-
问题是 bindingRedirect 起作用了。正如异常消息所说,它想要 4.0.0.0,但您却给了它 4.1.0.0。想要一劳永逸地解决这个问题的程序员数量必须相当多。
标签: c# visual-studio-2015 app-config