• 程序集冲突问题


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

  • 相关阅读:
    第09组 Alpha冲刺(3/4)
    第09组 Alpha冲刺(2/4)
    第09组 Alpha冲刺(1/4)
    数值分析——多项式插值之Lagrange插值
    Deepin下安装搭建latex编写环境
    Deepin下安装Matlab2017a永久版
    数学建模方法-遗传算法(实战篇part 2)
    数学建模方法-遗传算法(实战篇part 1)
    数学建模方法-遗传算法(理论篇)
    Deepin系统下MATLAB中文字体乱码问题解决(加上字体美化)
  • 原文地址:https://www.cnblogs.com/karl-F/p/6482771.html
Copyright © 2020-2023  润新知