3
votes

I am trying to install Unity.Mvc4 but I get this error message;

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

The version of Microsoft.Practices.Unity I have is 3.0.0.0. Why would I want an older version?

2
If you want to use Unity 3, get the Unity bootstrapper for ASP.NET MVC instead of Unity.MVC4. The linked project is managed by Microsoft while Unity.MVC4 is not.Jasen

2 Answers

6
votes

Unity.Mvc4 is a community project and references an older version of Unity. If you want to use Unity.Mvc4 you can get an older version of Unity from the Package Manager Console you should use the following (see this post for more information)

Install-Package Microsoft.Practices.Unity -Version <press tab key for autocomplete>

From personal experience: If you want or need to use newer versions of Unity (which has good support for MVC and Web API in version 3) you should try to get rid of packages like Unity.Mvc4 or Unity.WebApi. They are useful for older projects (where Unity 3 is not a choice), but for new projects Unity has all you normally need.

2
votes

I had a similar problem with Unity 3. Instead of installing another version of unity I just changed the assembly binding in the web.config:

     <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.5.0.0"/>
  </dependentAssembly>