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

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

问题描述

昨天,我已经实现了代码:

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:

非泛型方法
'微软。 Practices.Unity.IUnityContainer.Resolve(System.Type的,
字符串,则params
Microsoft.P​​ractices.Unity.ResolverOverride [])'
不能与类型参数

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

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

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

P.S。

行使用Microsoft.P​​ractices.Unity; ,是目前在usings栏目

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));

和得到了另一个错误:

没有过载方法'解决'需要
'1'的参数

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

这似乎是一个大会不被引用..但哪一个?我曾其中2引用:
1. Microsoft.P​​ractices.Unity.dll
2. Microsoft.P​​ractices.ServiceLocation.dll

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。我已经看到了类似的问题, http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId= 8205 但它解析为不是一个错误

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"

任何想法会有所帮助。

推荐答案

我有同样的问题,找到了修复看着棱镜示例代码文件。看起来,即使它不是在Unity V2一个dll,你必须在你的类添加一个参考:
Microsoft.P​​ractices.Unity

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

我的完整用部分如下

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



我不知道,如果你正在使用Silverlight,但通用版本Container.Resolve <强>是在Microsoft.P​​ractices.Unity。

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;引发Error声称它不能与类型参数一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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