0

I have several .net-ConsoleApplications with a lot of app.config-Files.

In each app.config I have the following section:

   <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-5.2.9.0" newVersion="5.2.9.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

This works fine, but now I have updated the nuget-packages and have to update all binding redirects. This is a lot of manual work.

I've read in the internet of the linkedConfiguration-Element where I can move the bindingRedirects to another file. So I replaced the above code with the following:

  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <linkedConfiguration href="file://D:\Sources\AssemblyBindingRedirects.xml"/>
  </assemblyBinding>
  <runtime>
  
  </runtime>

and the AssemblyBindingRedirects.xml is:

<?xml version="1.0"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-5.2.9.0" newVersion="5.2.9.0"/>
      </dependentAssembly>          
    </assemblyBinding>
  </runtime>
</configuration>

In the web.config of an IIS-Application this just works fine. Unfortunately in my app.Config-Files this doesn't work. I get an error that the Newtonsoft.Json.dll in the Verison 6.0.0.0 could not be found.

What am I doing wrong here?

Tomtom
  • 9,087
  • 7
  • 52
  • 95

0 Answers0