The type 'IUnityContainer' is defined in an assembly that is not referenced The type 'IUnityContainer' is defined in an assembly that is not referenced asp.net asp.net

The type 'IUnityContainer' is defined in an assembly that is not referenced


This might be an more updated answer for how to upgrade from Unity 3.5.1 to 4.0.1.

The type 'IUnityContainer' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Either via Package Manager Console or NuGet:

  • Uninstall Unity.Mvc4
  • Uninstall Unity.WebAPI
  • Update-Package Unity
  • Install-Package Unity.Mvc (note: no number in package name this time)
  • Install-Package Unity.AspNet.WebApi

Code:

  • Copied container.RegisterTypes from Bootstrapper.cs to App_Start/UnityConfig.cs
  • Exclude Bootstrapper.cs from project
  • Build and Run


Well, this is probably superfluous now, but the issue apparently had something to do with Unity 3.5.1406, as that got pulled down, and replaced with Unity 4.0. I also replaced the older, apparently unsupported Unity.WebApi library that hasn't been updated in several years, and replaced it with the newer, apparently supported Unity.AspNet.WebApi library. That's a little tricky in NuGet, as a search for "Unity WebApi" returns the older library at the top of the list, and hides the newer library down off the bottom of the first page.

Between all that, it works now, without any issues I've spotted.


I hit this when running a global update-package.

Rolling back the Unity version via install-package Unity -version 3.5.1404 solved it.