I have an IIS-Server-Application where I want to set binding-redirects in another file which can be used by other parts of my entire system.
I've read about the linkedConfiguration
-Element for this purpose.
So in the web.config I had the following redirects:
<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>
I replaced this with the following:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<linkedConfiguration href="file://D:\Dev\IIS\AssemblyBindingRedirects.xml"/>
</assemblyBinding>
And the content of the AssemblyBindingRedirects.xml is:
<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>
Unfortunately this doesn't seem to work. I get an error, that an incorrect version of Newtonsoft.Json was detected at runtime. I've already checked that the AssemblyBindingRedirects.xml exists in the correct directory and is present at runtime.
What am I doing wrong?
In the web.config
the linkedConfiguration
-Element is a child of the runtime
-Element. That is the problem. If I move it outside of the runtime
-Element it works.
But only if I use a full qualified path at the href
-Attribute. If I try to use a relative path it doesn't work because relative paths are not allowed in web.config