Assembly binding redirect does not work
Solution 1
Any typo in configuration xml can be a cause. Loader just can't see your configuration. I also had a hour of headache until I realize that the error was in character "=" instead of "-" in schema name:
<assemblyBinding xmlns="urn:schemas=microsoft-com:asm.v1">
Just check carefully all attribute names and values. I guess "PublicKeyToken" should be "publicKeyToken"
This should work:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.AnalysisServices" publicKeyToken="89845dcd8080cc91" />
<bindingRedirect oldVersion="10.0.0.0" newVersion="9.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Solution 2
Make sure your <configuration>
tag has no namespace attribute. Otherwise any <assemblyBinding>
tag will be ignored.
Wrong:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
Right:
<configuration>
(from https://stackoverflow.com/a/12011221/150370)
Solution 3
I encountered assembly binding redirect not working, because of a missing namespace on the assemblyBinding element.
Correct
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="TIBCO.Rendezvous" publicKeyToken="1a696d1f90f6158a"/>
<bindingRedirect oldVersion="1.0.0.0-1.0.3191.28836" newVersion="1.0.3191.28836"/>
</dependentAssembly>
Incorrect
Note missing: xmlns="urn:schemas-microsoft-com:asm.v1"
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="TIBCO.Rendezvous" publicKeyToken="1a696d1f90f6158a"/>
<bindingRedirect oldVersion="1.0.0.0-1.0.3191.28836" newVersion="1.0.3191.28836"/>
</dependentAssembly>
Solution 4
in my case, i had to remove the
appliesTo="v2.0.05727"
from
<assemblyBinding appliesTo="v2.0.05727" xmlns="urn:schemas-microsoft-com:asm.v1">
Solution 5
I've had similar issue where moving bindingredirects to Machine.Config was the only thing that worked. That was not ideal solution in my winform app because I distribute my app to clients.
Solution:
Make sure .config file is in the directory where your application is running from. e.g. if your AppName is "MyApp" then Redirects should be in "MyApp.exe.Config" file in application directory.
I had to do this even if the code that uses third party dlls is in different dll in my solution and adding .dll.config didn't help.
Admin
Updated on August 05, 2022Comments
-
Admin over 1 year
I'm trying to set up an assembly binding redirect, using the following app.config:
<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.AnalysisServices" PublicKeyToken="89845dcd8080cc91" /> <bindingRedirect oldVersion="10.0.0.0" newVersion="9.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
I'm running the program on a machine with version 9.0.242.0 in the GAC, with the specified public key token. The CLR doesn't seem to be even trying to redirect the binding to use that version though.
Here is what I get in fuslogvw.exe:
LOG: This bind starts in default load context. LOG: Using application configuration file: \Debug\AssemblyRedirectPOC.exe.Config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Post-policy reference: Microsoft.AnalysisServices, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices.DLL. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices/Microsoft.AnalysisServices.DLL. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices.EXE. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices/Microsoft.AnalysisServices.EXE. LOG: All probing URLs attempted and failed.
When I tried putting the 9.0.242.0 version dll in the probe path, I get this instead:
LOG: Assembly download was successful. Attempting setup of file: \Debug\Microsoft.AnalysisServices.dll LOG: Entering run-from-source setup phase. LOG: Assembly Name is: Microsoft.AnalysisServices, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: The assembly reference did not match the assembly definition found. ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Note that I also tried changing the redirect to use "9.0.242.0" instead of "9.0.0.0" in the app.config and that didn't work, although I don't think it should make any difference.
From what I understand the whole point of redirecting a binding is to use a version that does not match that which the program was built with. Am I completely missing something here? Is what I'm trying to do possible, and if so, any idea of why it's not working?
Cheers, Adam
-
trailmax almost 11 yearsadding
xmlns="urn:schemas=microsoft-com:asm.v1"
solved the problem for me. Thanks! -
Zack almost 10 yearsThe wrong one (with an = instead of -) worked for you?
-
Ziggler about 8 yearsMoving bindingredirects to Machine.Config solved my issue.
-
Ziggler about 8 yearsMoving bindingredirects to Machine.Config solved my issue
-
Sören Kuklau over 5 yearsThis was the answer. The binding redirects were silently ignored because my
web.config
was so old it had the 2.0 namespace. -
Stan over 5 yearsTry moving <runtime> section higher in web.config. Start with right under <configuration>. Much better than machine.config!
-
JumpingJezza about 5 yearsThank you! This happened to me upgrading from VS2015 to VS2017. No errors - just wouldn't publish :( :( :(
-
fernacolo over 4 yearsOne common mistake is making bad XML comments. For instance if you add
--
(double-hyphen) inside a comment instead of only at the end mark, the entire XML cannot be read. -
hongsy over 4 yearshi and welcome to StackOverflow! Please consider adding some explanation and details to your answer.
-
Ricardo Saracino over 3 yearsThis might be worth noting for the uninitiated, make sure the dependency is in the Assemblies folder
-
Stefan about 3 yearsThanks, that really helped! It seems that due to this problem some or all of redirects were ignored.
-
callee.args almost 3 years2 hrs of headache and then the solution was as simple as removing ns.
-
jtsoftware over 2 yearsTo clarify, for me it was the (appName).exe.config file that needs to be copied alongside the main (appName).exe file.
-
yoni over 2 yearsplease notices that the 'xmlns' tag, must be present on each and every 'assemblyBinding', plus, my case ended with adding assemblyBinding tag between every dependentAssembly
-
Kobold_Warlord about 2 yearsJust spent hours on this issue. After trying my usual assortment, THIS was the answer. Older .NET 2.0 app that was updated to 4+, and the configuration node still had that namespace. Thank you!
-
drzounds about 2 yearsSame here but I wonder why when impersonate is set on IIS authentication for the site dependentAssembly breaks?