.NET can be very painful to develop as new versions of System packages are released, and you happen to use a library that adopts the new version. The new versions contains some additional APIs that the library uses, and if you use an older one, your program may still run, but crash at run time with MethodNotFoundException because the older DLL doesn't contain a particular method defined.
Even when you ship the latest version, you can still have a problem. For instance, one library uses System.Net.Http 4.2.0.0 another uses System.Net.Http 4.3.0.0, and you ship 4.3.0.0 with the application, the library that uses 4.2.0.0 will look for exactly version 4.2.0.0, and crash your program since you didn't have the same version included. The .NET team anticipated this and allow your program to redirect 4.2.0.0 to 4.3.0.0, this is known as a binding redirect.
Once you have a lot of binding redirects, it's impossible to manage by hand.
The best way is to have the computer do this automatically for you. Update the .csproj file so it contains an AutoGenerateBindingRedirects tag.
<Project>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
</Project>
Next, update your app.config or web.config and remove all binding redirects
<configuration>
<runtime>
<!-- REMOVE THE ENTIRE SECTION START -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
</assemblyBinding>
<!-- REMOVE ENTIRE SECTION END -->
</runtime>
</configuration>
When you build the application, and you inspect the bin\Debug\YOURAPP.exe.config you will find binding redirects has been added automatically so that all the libraries look for a single version of a DLL.
Additional steps for Web Applications
If you have a web.config, then the process is different. Since Web.config needs to be shipped to the production machine, it needs the correct assembly binding redirect added. Visual Studio will compute the assembly binding redirects required, and show a build warning.
When you double click on the build warning, the correct assembly binding redirect will be added to your web.config.
Additional checks
If you use packages.config, then you should check that your .csproj
is referencing the same versions of nuget defined in the packages.config.
However, if you are building an .exe, and not a web application, I recommend you convert your project to use PackageReference instead. Visual Studio will ensure the same version is referenced automatically and you will not have to check.