问题
I am working on a web-based application using asp.net 4.0.
I have some dlls I am using in the GAC that have some embedded dependencies on older dlls.
I have Configured the assemblies so that the dependency redirects to the correct version of the dll on my machine. This works perfectly in a 3.5 or lower version application, however, when I try to build an asp.net 4.0 application based on the same dlls, it chokes with an error like:
Could not load file or assembly 'ControlReferencedByMyDll, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXX' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
where my version of ControlReferencedByMyDll is version 2.0.1.0.
I could not find a GAC configuration utility for .net 4.0, but in my machine.config (In both the Framework and Framework64 folders for .net 4.0) I have added something like:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ControlReferencedByMyDll" PublicKeyToken="XXXXXXXXXXXXXXXX"/>
<bindingRedirect oldVersion="1.0.0.0-9.9.9.9" newVersion="2.0.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
to see if that was the problem.
I've even tried to add the appliesTo="v2.0.50727" attribute to the assemblyBinding to see if it made a difference.
but it does not seem to have.
Has anyone else had this problem? and more importantly, can anyone help me solve this?
回答1:
I do not know if it helps after so long, but I had the following problem.
I had a redirect like:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="test.dll" PublicKeyToken="XXXXXXXXXXXXXXXX"/>
<bindingRedirect oldVersion="1.0.0.0-9.9.9.9" newVersion="2.0.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
And, although it worked in previous versions, it was not working on 4.0 either.
I removed the ".dll" from the name, and now it works!!!
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="test" PublicKeyToken="XXXXXXXXXXXXXXXX"/>
<bindingRedirect oldVersion="1.0.0.0-9.9.9.9" newVersion="2.0.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Hope it helps the next poor guy who cracks his head for a couple of hours.
回答2:
Okay, I haven't seen any additional feedback, and at this point, I have not determined if/where the .config file is being overridden between machine.config and web.config, but this is what works.
I add code similar to the following:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ControlReferencedByMyDll" PublicKeyToken="XXXXXXXXXXXXXXXX"/>
<bindingRedirect oldVersion="1.0.0.0-9.9.9.9" newVersion="2.0.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Directly to my web.config file.
I am submitting this as an answer to my own question, but as indicated before, if you happen to know a better way, or know what's causing the disconnect between machine.config and web.config, please share.
Thank you
来源:https://stackoverflow.com/questions/8174263/how-do-i-make-assembly-redirection-work-in-a-net-4-0-web-app