I get this error:
Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
How do I resolve this with an assembly redirect binding, if I already have another existing version of Microsoft.Practices.ServiceLocation
in my project?
Best Answer
One method is to recompile all NuGet packages to use the same version of
Microsoft.Practices.ServiceLocation
. At a pragmatic level, this just isn't practical: we need an easier method.A better method is to use an assembly binding redirect. This works very nicely, if the interface is the same. This solution is tried and tested, and is running in production in a number of FTSE companies.
This is what the app.config looks like:
Adjust the target version to whatever version you already have, which is typically
1.2.0.0
or1.3.0.0
.The
PublicKeyToken
must match the target assembly. You can extract it using the following command:Example:
For other ways of obtaining the
PublicKeyToken
, see Getting the PublicKeyToken of .Net assemblies.The
PublicKeyToken
does not change with the assembly version, e.g. its the same if the assembly isv1.0.0.0
orv2.0.0.0
.