3

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?

arame3333
  • 9,887
  • 26
  • 122
  • 205
  • 1
    If you want to use Unity 3, get the [Unity bootstrapper for ASP.NET MVC](https://www.nuget.org/packages/Unity.Mvc/3.0.1304) instead of _Unity.MVC4_. The linked project is managed by Microsoft while Unity.MVC4 is not. – Jasen Feb 07 '14 at 00:59

2 Answers2

6

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.

Community
  • 1
  • 1
Horizon_Net
  • 5,959
  • 4
  • 31
  • 34
  • I am finding that when I uninstall Unity via Nuget, and then install the new version of Unity, I still get the runtime error referring to version 2.1.505.0 Yet when I do a global search in my application, that version number simply does not exist. So I do not know how this version keeps being referred to. – arame3333 Feb 07 '14 at 08:10
  • You have to uninstall the bootstrapper(s), that means the references to **Unity.Mvc4** and/or **Unity.WebApi**. A tip for uninstalling a NuGet package: Instead of uninstalling it via the *Manage NuGet Packages* window you should delete the appropriate DLL and remove the appropriate line in the *packages.config* file. My experience so far is that when uninstalling via the window dependencies were also deleted regardless of whether they are needed by other packages. – Horizon_Net Feb 07 '14 at 12:54
2

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>
Arjan Hordijk
  • 141
  • 1
  • 5