2

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?

CStroliaDavis
  • 392
  • 4
  • 14
  • Okay, I found something that seems to work, although I'm still interested in seeing a better answer if one exists, and perhaps someone can enlighten me on why this works. I just placed the code indicated above directly into my web.config, and all is well. – CStroliaDavis Nov 17 '11 at 21:58
  • Related: http://stackoverflow.com/questions/16678395/assemblybinding-bindingredirect-not-working-for-mvc4-app-with-t4mvcextensions – user423430 Oct 10 '14 at 19:16

2 Answers2

5

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.

Dream Eye
  • 51
  • 1
  • 2
0

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

CStroliaDavis
  • 392
  • 4
  • 14