有兩個類庫項目,一個引用了比如Newtonsoft.Json 6.0, 另一個引用了比如Newtonsoft.Json 8.0, 然后另一個exe項目同時引用了這兩個類庫項目。
那么在編譯的時候會報warning:
No way to resolve conflict between "Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily. Consider app.config remapping of assembly "Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" from Version "6.0.0.0" [DllProject1\bin\Release\Newtonsoft.Json.dll] to Version "8.0.0.0" [DllProject2\bin\Release\Newtonsoft.Json.dll] to solve conflict and get rid of warning. |
然后exe在運行的時候會報錯:
Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. |
【解決方法】
在exe項目的app.config加入如下的配置:
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> |