【问题标题】:Have two separate versions of a dll有两个不同版本的 dll
【发布时间】:2016-12-23 01:38:14
【问题描述】:

我有一个 Web 表单应用程序,它的所有业务逻辑都在一个单独的 dll 中,并带有它自己的项目。 dll 需要有两个不同版本的 Newtonsoft.json。我尝试在网站 web.config 和 dll app.config 文件中使用以下代码,但我无法让应用程序从我指定的文件夹加载 dll:s。我仍然收到消息:

“无法加载文件或程序集 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(来自异常HRESULT: 0x80131040)"

关于我可能做错了什么有什么想法吗?

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <!--<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />-->

    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken ="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="4.5.0.0" newVersion="5.0.1.0" />
    <bindingRedirect oldVersion="5.0.2.0-99.0.0.0" newVersion="7.0.1.0" />
    <codeBase version="4.5.0.0" href="Bin/Newtonsoft.Json/5.0.1.0/Newtonsoft.Json.dll" />
    <codeBase version="5.0.1.0" href="Bin/Newtonsoft.Json/5.0.1.0/Newtonsoft.Json.dll" />
    <codeBase version="7.0.1.0" href="Bin/Newtonsoft.Json/7.0.1.18622/Newtonsoft.Json.dll" />

    <!--<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.1.0" />-->

  </dependentAssembly>
</assemblyBinding>

已解决:在 webconfig 和 appconfig 中添加以下内容 &lt;bindingRedirect oldVersion="0.0.0.0-99.0.0.0" newVersion="7.0.1.0" /&gt;

【问题讨论】:

  • 我想知道你为什么需要这样做......
  • 我使用 Dropbox.API 和 Hangfire,他们使用不同版本的 Newtonsoft.Json
  • 为什么需要两个版本?
  • 不要在您的问题中添加Solved,将其作为答案发布并接受。您还需要在文本周围加上反引号 `,否则网站会认为它是 HTML 并将其删除。
  • 另外,让未来的版本倒退通常不是一个好主意,代码可能依赖于较新版本中的功能,最好使用oldVersion="0.0.0.0-7.0.1.0" newVersion="7.0.1.0" 并修复newVersion 字段如果您更新到较新的版本。

标签: .net dll


【解决方案1】:

在 webconfig 和 appconfig 中添加以下内容 &lt;bindingRedirect oldVersion="0.0.0.0-99.0.0.0" newVersion="7.0.1.0" /&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多