Fixing assembly redirects issue quickly
One of the most frustrating issues faced by .NET developers during application development can be narrowed down to two or three top issues - one of it is Assembly Binding redirects issue. And I have been its victim quiet lot of time.
It starts with updating simple / single NuGet package that is critical for your project, then issue spreads into multiple dependencies through new conflicts until you reach a meltdown ;). You might scrap out your recent change and try a different path with no success.
Well, you are in luck!
Understanding this dependency graphs is tougher for humans, but a lot easier for binary beings. And all this time, you have a tool that does this and yet you don't seem to notice it yet (It did happen for me)
I've recently found this simple solution and its gem. You can just run following command in
Package Manager Console to fix the redirects properly in all your projects within seconds.
PS> Get-Project –All | Add-BindingRedirect
This will solve your miseries in no time.
In case, your issue is not yet resolved after above command let execution. Then your assembly redirects section seems to be messed up too much with different incompatible redirects, which might have resulted in wrong ones even for the PS command.
So, to properly fix all redirects follow below steps
- Remove all
assemblyBindingredirects from web.config
- Add following to the .csproj file
<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>
- Build the project. Go to the bin folder, there should be a (WebAppName).dll.config file.
- Open and copy the correct assembly redirects from there, to your web.config
- Remove the additional tags added in step 3 from .csproj file