程序集冲突问题

今天遇到一个奇怪的问题,我的A类库引用了Newtonsoft.Json.dll (8.0.0.0),主程序应用了A类库,发现程序运行时报错,提示无法加载Newtonsoft.Json.dll,后来发现Newtonsoft.Json.dll未输出到主程序Bin目录,重新连接类库编译都不能解决问题,仔细发现编译有个Warning 提示,如下:

 

No way to resolve conflict between "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
8> Consider app.config remapping of assembly "Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" from Version "8.0.0.0" [D:\work\XXXXXXX\bin\Debug\Newtonsoft.Json.dll] to Version "9.0.0.0" [] to solve conflict and get rid of warning.

奇怪的是我没有程序集或类库引用了9.0的版本,怀疑之前是使用Nuget管理,自动升级到8.03版本,后来引用本地引用8.0的版本,也不知道具体原因,网上找方案,最终如下方法解决:

在主程序的App.config中加入如下

<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="9.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

重新编译解决。

 

相关信息查看

 

publicKeyToken可以通过Develper command prompt for vs2012工具查看,

sn -T dll路径

 

 

posted @ 2017-03-01 09:44  碎心炼心  阅读(483)  评论(0编辑  收藏  举报