30

An hour ago I updated my nuget packages for the solution I'm working on and I get the error message, thrown by Unity, that

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

Since then I have been googling to get some usable information about that where this package is. The articles, question around it are old, deals with 2.x version.

There is no such package in Nuget.

I have the packages listed below from Unity stack installed:

  <package id="Unity" version="4.0.2" targetFramework="net452" />
  <package id="Unity.ServiceLocator" version="2.0.0" targetFramework="net452" />
  <package id="Unity.WebAPI" version="5.2.3" targetFramework="net452" />

Any help is appreciated!

AndrasCsanyi
  • 3,943
  • 8
  • 45
  • 77

3 Answers3

36

I had to change

using Microsoft.Practices.unity;

to

using Unity;

I think because of an update in Unity with NuGet

Alvaro Rodriguez Scelza
  • 3,643
  • 2
  • 32
  • 47
  • 1
    Thanks; you saved me a couple of hours – Stefan Jan 07 '18 at 18:53
  • 1
    IN my case i am only installing the Unity.WebAPI Nuget. But its failing.Its searching for the Using UNity; although i have installed it i can't see it – lokanath das Oct 01 '18 at 10:31
  • @lokanathdas i am facing the same problem. I have installed unity 5.11.4 but it gives me error when i am trying to resolve class (container.Resolve()) . Error = CS0308 The non-generic method 'IUnityContainer.Resolve(Type, string, params ResolverOverride[])' cannot be used with type arguments – Mashhad Saleem Sep 15 '20 at 07:40
22

After adding the nuget with

Install-Package Unity

it is located in

packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll 

You probably just need to add a reference to this assembly.

Martin Staufcik
  • 8,295
  • 4
  • 44
  • 63
  • 1
    I installed a wrong package, 4.0.2 published by AgileSight. The 4.0.1 - which references automatically the Miicrosoft.Practices.Unity.dll - was published by Microsoft and working like a charm. – AndrasCsanyi Feb 28 '16 at 11:45
0

Update Unity with Nuget. I use NuGet Package Manager instead of command line. Access Manager by right-clicking the solution in the Solution Explorer from Visual Studion

Tomas Hesse
  • 385
  • 3
  • 10