gpt4 book ai didi

c# - IUnityContainer.Resolve 抛出错误,声称它不能与类型参数一起使用

转载 作者:IT王子 更新时间:2023-10-29 03:40:53 25 4
gpt4 key购买 nike

昨天我实现了代码:

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

它是可编译的并且可以工作。

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

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

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

附言

行“使用 Microsoft.Practices.Unity;”存在于使用部分。

我尝试用非通用版本替换通用版本:

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

还有一个错误:

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

似乎没有引用其中一个程序集..但是是哪一个?我引用了其中的两个:1.微软.Practices.Unity.dll2.微软.Practices.ServiceLocation.dll

附言我见过类似的问题 http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=8205但它被解决为“不是错误”

任何想法都会有帮助

最佳答案

我遇到了同样的问题,并在查看 Prism 示例代码文件时找到了“修复”。看起来,即使它不是 Unity V2 中的 dll,您也必须在您的类中添加对以下内容的引用: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 IS 在 Microsoft.Practices.Unity 中的通用版本。

关于c# - IUnityContainer.Resolve<T> 抛出错误,声称它不能与类型参数一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2875429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com