IUnityContainer.Resolve< T> throws错误声明它不能与类型参数一起使用 [英] IUnityContainer.Resolve<T> throws error claiming it cannot be used with type parameters

查看:750
本文介绍了IUnityContainer.Resolve< T> throws错误声明它不能与类型参数一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我实现了代码:

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

这是可编译和正常工作。



今天(可能我修改了一些东西)我经常收到错误:


非通用方法
'Microsoft。 Practices.Unity.IUnityContainer.Resolve(System.Type,
string,params
Microsoft.Practices.Unity.ResolverOverride [])'
不能与类型参数一起使用


我的collegue有相同的源代码,没有相同的错误。为什么?如何解决这个问题?





lineusing Microsoft.Practices.Unity;



我试图用非泛型版本替换泛型版本:

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

出现另一个错误:


方法'Resolve'没有重载
'1'参数


组件没有被引用..但是哪一个?我有其中2个引用:
1. Microsoft.Practices.Unity.dll
2. Microsoft.Practices.ServiceLocation.dll



P.P.S。我看到类似的问题 http://unity.codeplex.com/WorkItem/



任何想法都会有所帮助


<我有同样的问题,发现了修复看Prism示例代码文件。看起来像,即使它不是在Unity V2中的dll,你必须在你的类中添加一个引用:
Microsoft.Practices.Unity



我完整的使用部分如下

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

我不知道你是否使用Silverlight,但是Container.Resolve的泛型版本 IS 在Microsoft.Practices.Unity中。


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

解决方案

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.

这篇关于IUnityContainer.Resolve&lt; T&gt; throws错误声明它不能与类型参数一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆