IUnityContainer.Resolve<T>抛出错误,声称它不能与类型参数一起使用 [英] IUnityContainer.Resolve&lt;T&gt; throws error claiming it cannot be used with type parameters

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

问题描述

昨天我已经实现了代码:

Yesterday I've implemented the code:

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

它是可编译和工作的.

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

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

非泛型方法'Microsoft.Practices.Unity.IUnityContainer.Resolve(System.Type,字符串,参数Microsoft.Practices.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

我的同事有相同的源代码并且没有相同的错误.为什么?如何解决问题?

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

附言

行使用 Microsoft.Practices.Unity;"存在于 using 部分.

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

还有一个错误:

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

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

似乎没有引用其中一个程序集..但是哪个程序集?我引用了其中的两个:1.Microsoft.Practices.Unity.dll2. Microsoft.Practices.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"

任何想法都会有所帮助

推荐答案

我遇到了同样的问题,并在查看 Prism 示例代码文件时找到了修复".看起来,即使它不是 Unity V2 中的 dll,您也必须在类中添加一个引用:Microsoft.Practices.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

我完整的使用"部分如下

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;

我不确定您是否使用 Silverlight,但不确定您是否使用的是 Microsoft.Practices.Unity 中 Container.Resolve IS 的通用版本.

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

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

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