Fixing binding redirects for a large project

972 Views Asked by At

I have a solution that contains a Web API project that references several other projects. There's another project in there that contains a bunch of Azure functions, and a few projects for old deprecated worker roles.

Binding redirects and Nuget has been the bane of my existence. I get a lot of dependency errors, which seem to vary depending on what platform I run my program on:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

My best guess after some research is that the Web API loads the first set of DLLs using its own binding redirect rules, and if another project needs a different DLL as specified by a different binding redirect, it can't find it and fails.

I found I was able to fix my project by consolidating all my nuget packages and making all the binding redirects match the Web API's binding redirects... however, now everything seems to work except VSTS tests, which continue to generate FileNotFoundExceptions for the DLLs.

So, instead of just asking SO to fix my project for me (and it would be difficult since it's so large), I'm more interested in what's the rule of thumb for large projects like mine that have a bunch of problems with dependencies? E.g., should all the binding redirects be the same, or is it okay if they differ? Should I organize my dependencies in some other way? What would you do to untangle this?

1

There are 1 best solutions below

1
On

Maybe it helps to:

  • Make sure the dependencies of dependencies use the same package versions (this can cause the error to happen, i.e. Project A uses Project B, and Project B uses Package v4.0, while project A uses Package v4.1.

  • Make sure in the "Project A/Project B" example that if Project A directly uses a dll, that Project B does it too, or use a nuget package for both.

This can be very time consuming in my experience, so good luck!

PS: This command for the package manager console can help too:

Update-Package -ProjectName YourProject -reinstall