IUnityContainer.Resolve <T> throws an error stating that it cannot be used with parameters of type

Yesterday I injected the code:

CustomerProductManager productsManager = container.Resolve<CustomerProductManager>(); 

It was compiled and working.

Today (maybe I changed something) I constantly get an error:

The non-generic method "Microsoft.Practices.Unity.IUnityContainer.Resolve (System.Type, string, params Microsoft.Practices.Unity.ResolverOverride [])" cannot be used with arguments of type

My college has the same source code and does not have the same error. What for? How to solve a problem?

PS

string "using Microsoft.Practices.Unity;" present in the "Usage" section.

I tried replacing the generic version with a non-generic one:

 CustomerProductManager productsManager = (CustomerProductManager)container.Resolve(typeof(CustomerProductManager)); 

And I got another error:

There is no overload for the Allow method. Arguments '1'

It seems that one of the collections is not indicated .. but which one? I have 2 of them: 1. Microsoft.Practices.Unity.dll 2. Microsoft.Practices.ServiceLocation.dll

PPS I saw a similar problem http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=8205 , but it is resolved as "not an error"

Any thought will be helpful.

+66
generics c # compilation unity-container
May 20, '10 at 15:46
source share
5 answers

I had the same problem and found a β€œfix” by looking at the Prism example code files. It looks like even if it's not a dll in Unity V2, you need to add the link to your class: Microsoft.Practices.Unity

my full Usage section is as follows

 using System; using System.Windows; using Microsoft.Practices.Composite.Modularity; using Microsoft.Practices.Unity; using Microsoft.Practices.Composite.UnityExtensions; 

I'm not sure that you are using Silverlight, but the generic version for Container.Resolve IS is at Microsoft.Practices.Unity.

+165
Jul 28 '10 at 15:23
source share

Microsoft no longer owns Unity, and in version 5, the namespace:

 using Unity; 

Make sure your use section uses:

 container.Resolve<T>(); 
+10
Mar 28 '18 at 22:38
source share

I ran into this problem and none of these answers helped me. I was getting a compile time error

Unknown RegisterType () method Microsoft.Practices.Unity.IUnityContainer

for my code below.

Container.RegisterType<MyInterface, MyClass>();

I found that if you did not implement IMyInterface in the MyClass class, you will get this problem. Hope he solves you too ...

+1
Dec 09 '13 at 23:51
source share

In my situation, I wrapped a class in Unity inherited from an abstract base class, and this base class had a NOT constructor without parameters. As soon as I changed my code to use the constructor without parameters for the base class, the problem disappeared.

0
Oct 10 '13 at 17:21
source share

In my situation, I had a Bootstrapper that implemented its own Resolve without a generic version, so it could not find a Microsoft Unity Resolve solution. Adding the right use did the trick.

0
May 31 '16 at 16:16
source share



All Articles