zoukankan      html  css  js  c++  java
  • 程序集冲突问题

    今天遇到一个奇怪的问题,我的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:workXXXXXXXinDebugNewtonsoft.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路径

  • 相关阅读:
    Linux命令全训练
    解决maven中静态资源只能放到properties中的问题
    Mybatis出现错误org.apache.ibatis.executor.ExecutorException: No constructor found in
    Fence Repair
    Saruman's Army
    Best Cow Line
    区间调度问题
    硬币问题
    迷宫最短路径
    Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch
  • 原文地址:https://www.cnblogs.com/karl-F/p/6482771.html
Copyright © 2011-2022 走看看