views:

428

answers:

3
+1  Q: 

Unity doesn't work

Yesterday I've implemented the code:

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

It was compilable and working.

Today (probably I've modified something I am constantly getting the error:

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

My collegue has the same source code and doesn't have same error. Why? How to resolve the problem?

P.S.

line "using Microsoft.Practices.Unity;" is present in usings section.

I've tried to replace generic version with non-generic one:

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

And got another error:

No overload for method 'Resolve' takes '1' arguments

It seems like one of the assemblies is not referenced.. but which one? I have 2 of them referenced: 1. Microsoft.Practices.Unity.dll 2. Microsoft.Practices.ServiceLocation.dll

P.P.S. I've saw similar problem http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=8205 but it is resolved as "not a bug"

Any thought will be helpful

A: 

I was not able to did this workable on my machine, because 'other guy' corrected solution version to be used by VS2008 SP1 only (I didn't have SP installed yet).

I've moved to another machine, with brand new Software installed, with VS2008+SP1 and now all is ok.

Ideas: 1. try to install SP1 2. try to reinstall Unity (I've tried just to update the refferences, that didn't help). 3. try to reinstall everything (crazy idea, but ... :) )

Budda
+5  A: 

I had the same problem and found the "fix" looking at Prism sample code files. Looks like, even if it is not a dll in Unity V2 you have to add a reference in your class to: Microsoft.Practices.Unity

my complete "using" section is as follow

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

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

rodrigo
Exactly. Some time ago I've detected that adding 'using Microsoft.Practices.Unity;' resolves an issue.
Budda
A: 

Adding of the additional using:

using Microsoft.Practices.Unity;

resolved an issue.

Budda