1

I have got a web application with multiple projects that is using newtonsoft 6.0.0.0. Now I have added a stripe dll to two of the projects which turns out that it needs higher newtonsoft. What I need to is that instead of upgrading all newtonsoft library across the web application projects, and also in other apps as there are some shared library, I want to limit the use of newtonsoft higher version to only stripe so that all projects still use the lower version even the projects using stripe can still use the lower version for non stripe logics.

What I tried so far is I added below to the project files:

      <ItemGroup>
        <!-- Place the new snippet here -->
        <Content Include="..\..\Comps\Json.NET\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <Link>Stripe\Newtonsoft.Json.dll</Link>
        </Content>
        <Content Include="..\..\Comps\Json.NET\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <Link>Newtonsoft.Json.dll</Link>
        </Content>
        
      </ItemGroup>

Also I added the lower version as a reference

<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <HintPath>..\..\Comps\Json.NET\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>    

I have also added this in Web.config

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
    <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="6.0.0.0" />
    <codeBase> version="6.0.0.0" href="Newtonsoft.Json.dll"</codeBase>
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
    <bindingRedirect oldVersion="9.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
    <codeBase> version="13.0.0.0" href="Stripe\Newtonsoft.Json.dll"</codeBase>
  </dependentAssembly>

But I am getting error loading the web app.

Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Any help to resolve this will be appreciated.

Palle Due
  • 5,929
  • 4
  • 17
  • 32
Jami
  • 579
  • 6
  • 20

2 Answers2

1

That will not work. It only takes the first redirect rule with a given assemblyIdentity. You can see that here

In case of a conflict in redirection, the first matching redirection statement in the configuration file is used.

Palle Due
  • 5,929
  • 4
  • 17
  • 32
  • Thanks, is there any practical way to the problem except for making all the dlls the same version across the projects? – Jami May 25 '23 at 11:11
  • Also how come this link's answer apparently works? https://stackoverflow.com/questions/5916855/using-multiple-versions-of-the-same-dll – Jami May 25 '23 at 12:03
  • That's interesting. When you look at the comments it apparently doesn't work for all users. Anyway, your redirects are wrong. I'll drop another answer. – Palle Due May 25 '23 at 12:48
0

Your xml is wrong. The attributes have been made content. It should look like this:

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
    <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="6.0.0.0" />
    <codeBase version="6.0.0.0" href="Newtonsoft.Json.dll"></codeBase>
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
    <bindingRedirect oldVersion="9.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
    <codeBase version="13.0.0.0" href="Stripe\Newtonsoft.Json.dll"></codeBase>
  </dependentAssembly>
Palle Due
  • 5,929
  • 4
  • 17
  • 32