0

Why do many assembly binding errors occur only after running an application and not at compile time? Is there a compiler switch to force a strong resolution of assembly bindings during compile?

Example:

We had an ASP.NET web project with NuGet packages for webapi v5.2.6 and it referenced a class library project with NuGet packages for web api v 5.2.3 (or the versions were switched vice versa, I do not recall specifically).

The project compiled fine and we deployed.

At runtime, it failed to startup with assembly binding errors stating that binaries for 5.2.3 could not be found.

We opened the solution back up, check NuGet consolidate, applied the consolidation recommendations, rebuilt, redeployed and everything worked fine.

ilkerkaran
  • 4,214
  • 3
  • 27
  • 42
cocogorilla
  • 1,815
  • 14
  • 36
  • 1
    there is the "specific version" flag on the [reference properties](https://stackoverflow.com/a/24022135/1132334). but that does not resolve problems with missing or mismatching assemblies after deployment. – Cee McSharpface Aug 01 '18 at 20:06
  • You can also resolve this by adding a binding redirect in your app.config or web.config. ``. With this present the application domain will resolve the requested assembly based on bindings configured here so an assembly needing `System.Web.Http` version `5.2.5.0` will be redirected to `5.2.6.0` instead. This works as long as the assemblies are backward compatible. – Igor Aug 01 '18 at 20:16

0 Answers0