Assembly mismatch despite having assembly redirect and loading correct version

前端 未结 2 849
粉色の甜心
粉色の甜心 2021-02-14 03:08

My console app uses System.Net.Http.Formatting v5.1.0.0 that depends on Newtonsoft.Json v4.5.0.0. My app however includes v6.0.0.0 of Newtonsoft.Json (for other reasons).

<
相关标签:
2条回答
  • 2021-02-14 03:13

    Just wanted to add a small amount of additional detail here, since this is a particularly nasty problem and garlic, silver bullets, and holy water are in short supply.

    We ran into this recently and discovered that the cause was schema-violating XML in the app.config resulting from a bad auto-merge, e.g.

    <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            <assemblyIdentity name="Microsoft.Extensions.FileProviders.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
    </dependentAssembly>
    

    We didn't notice the problem in the file since it's still technically valid XML and the Visual Studio parser never complained.

    The runtime binding routine, however, refused to apply any of the binding redirects (even ones stated outside of the malformed section). Furthermore, as alluded to above, there is no indication in the fusion logs that the runtime failed to parse the config file. It sees the correct dlls and config file location but still fails with a minor version discrepancy as if there was never any redirect applied.

    TL;DR - If you're getting this behavior, check to see that your config file XML is 100% perfect -- and don't trust that the squiggly lines in VS will reveal every possible problem.

    0 讨论(0)
  • 2021-02-14 03:27

    There is no evidence that your <bindingRedirect> is in effect. You should see:

    LOG: Redirect found in application configuration file: 4.5.0.0 redirected to 6.0.0.0.
    LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
    

    There are no breadcrumbs in your question, but whatever you edited appeared to not have been D:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe.Config. Odd drive letter. Beware of a project already having an App.config project item and you adding App1.config. Something like that.

    0 讨论(0)
提交回复
热议问题