What exactly does this line in the .csproj mean?
<Reference Include="Newtonsoft.Json, Version=22.214.171.124, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
First, let break down each line at a time:
<Reference Include= is an XML tag denoting an assembly reference into a project.
The text within the include tag Newtonsoft.Json, Version=126.96.36.199, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL is the fully qualified name of the .NET assembly.
<HintPath> denotes a location where Visual Studio will first attempt to look for the referenced DLL before starting to look in its probing paths.
As you can see, there are two file versions here, 1.0.2 and 188.8.131.52 which typically lead to confusion. However, when having a discussion around assemblies, it is best to stick with the one used in the fully qualified name, which in this case is 184.108.40.206. This is the version we use in the rest of this article.
So, why does all of this matter?
Different projects in a solution can use different versions of a DLL. For example, one project could rely v220.127.116.11 of Newtonsoft.Json while another one could rely on v18.104.22.168. However, when both projects are built to formulate the solution package, which one will be used, if both have the correct version of these assemblies in their hint paths?
As we all know, or we should, there cannot be two DLLs with the same name within a folder. So when our solution is deployed, there will be only one Newtonsoft.Json in the installation folder. The version deployed, will depend on the last project that was built and its output copied into the installation folder for our application.
But, what if we deployed v22.214.171.124 of the assembly? What would the assembly which relied on 126.96.36.199 of this assembly do, when it has to resolve its types?
This is where binding redirect for .NET comes in. In simple terms binding redirect instructs the .NET runtime on what version of an assembly to use if it cannot find the one that was specified in the assembly manifest. This is a configuration in app.config or web.config as typically looks like this:
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-188.8.131.52" newVersion="184.108.40.206" />
Basically, we are saying, her .NET runtime, if you are attempting to resolve an assembly called Newtonsoft.Json which has any version from 0.0.0.0 to 220.127.116.11, please look for an use Newtonsoft.Json version 18.104.22.168.
This will all work like magic but you better be sure Newtonsoft.Json 22.214.171.124 deployed alongside with your application and that this version is fully compatible with all versions within the range 0.0.0.0 to 126.96.36.199.