I just upgraded my ASP.NET MVC/WebApi project from Microsoft.Practices.Unity 3.5.1404 to 3.5.1406 (via nuget, just released). Afterwards, I'm getting this compile error:
Error CS0012 The type 'IUnityContainer' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Practices.Unity, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
On lines like:
GlobalConfiguration.Configuration.DependencyResolver =
new Unity.WebApi.UnityDependencyResolver(container);
Of course, I'm not referencing 3.0.0.0, but 3.5.1.0. So my assumption is that the Unity.WebApi
assembly has been compiled against an earlier version of the Microsoft.Practices.Unity
assembly. Theoretically, you'd want to fix that with an assembly redirect, like so:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.1.0" newVersion="3.5.1.0" />
</dependentAssembly>
However, that doesn't seem to work.
Any suggestions?
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:
Code:
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.
You need to make sure you also upgrade to Unity.AspNet.WebApi version 3.5.1406, not just Unity. If you do this, the error should go away.
I had the same issue this morning, ended up uninstalling v4.0 of Unity along with Unity.WebAPI. Installed v3.5.1405-prelease of Unity and then re-installed Unity.WebAPI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With