1

I'm creating a new MVC 4 website, and I'd like to use the Unity.MVC3 library to integrate with the DependencyResolver stuff built into MVC.

I also want to reference some data-access DLLs from an older, much larger project.

My problem is that Unity.MVC3 and the older DLLs are compiled against different versions of Unity, 1.2.0.0 and 2.1.505.0, respectively. I tried creating a binding redirect in my web.config file like so:

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersions="1.2.0.0-2.1.505.0" newVersion="2.1.505.0" />
  </dependentAssembly>

However, I still get the following error:

 Could not load file or assembly 'Microsoft.Practices.Unity, Version=1.2.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)

I turned on assembly binding logging, and the last two lines state:

 WRN: Comparing the assembly name resulted in the mismatch: Major Version
 ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Why isn't my binding redirect being respected? Is there a way to override its checking for major version conflicts?

Brian Sullivan
  • 27,513
  • 23
  • 77
  • 91

1 Answers1

2

There is a typo in the key token:

<assemblyIdentity name="Microsoft.Practices.Unity" 
     publicKeyToken="31bf856ad364e35" />

should be:

<assemblyIdentity name="Microsoft.Practices.Unity" 
     publicKeyToken="31bf3856ad364e35" />

Binding redirect does not complain in case of typos, it just does nothing.

I've made a test application, with this configuration it works:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.2.0.0" newVersion="2.1.505.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Pay attention to xmlns, without it, it fails silently.

Community
  • 1
  • 1
onof
  • 17,167
  • 7
  • 49
  • 85