'How to avoid Assembly binding in web.config for Newtonsoft.json and others?

I have a .Net WebAPI 2 project and latest version of Newtonsoft.Json My project is referencing 20 other projects and we have 50 instances in production, meaning 50 web.config files to maintain. Those environments are on our hosting but also some are on clients’ servers.

We are using same versions of Newtonsoft.Json in all projects, but for some reason, API project is adding AssemblyReference to web.config.

  <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>

When we switch off that option in project’s properties and start the API, it gives us error:

enter image description here

Microsoft.AspNet.WebApi.Cors which we use for enabling cross origin requests is dependant on Microsoft.AspNet.WebApi.Core, which is dependent on Microsoft.AspNet.WebApi.Client which is dependent on Newtonsoft.json

enter image description here

We cannot update all 50 production web.config files whenever we update Newtonsoft.Json or any other nuget package library.

Is there an alternative? We are using package.config in projects.

If somebody can help, that would be awesome. I could not find any related issue and solution to avoid updating dependentAssembly in web.config and avoid that completely.

If I want to remove Newtonsoft.Json from API project, this error occurs, which mean that all those libraries are using this package and in dependencies of those Nuget packages, version of Newtonsoft.Json is NOT latest. warning



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source