gpt4 book ai didi

caSTLe-windsor - 远程通用组件的异常 "an item with the same key has already been added"

转载 作者:行者123 更新时间:2023-12-04 06:54:04 26 4
gpt4 key购买 nike

出于各种原因,我正在尝试将项目从旧版本的 CaSTLe 升级到 v 2.5.3(由于重大更改,我无法移动到 v3)并且遇到了远程通用组件的问题:

   Container.Register(Component.For(typeof(IStore<>))
.Named("GenericStore")
.AddAttributeDescriptor("remoteserver", "RecoverableComponent")
.AddAttributeDescriptor("marshalByRefProxy", "true")
.ImplementedBy(typeof(MyStore<>)));

该组件似乎注册正常,但此时我尝试解决:

   Container.Resolve<IStore<Users>>()

我得到一个异常“已经添加了具有相同键的项目”和堆栈跟踪(缩短):

at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.Add(Object key, Object value)
at Castle.Facilities.Remoting.RemotingInspector.ConfigureServerComponent(RemotingStrategy server, Type type, ComponentModel model)
at Castle.Facilities.Remoting.RemotingInspector.ProcessModel(IKernel kernel, ComponentModel model)
at Castle.MicroKernel.ModelBuilder.DefaultComponentModelBuilder.BuildModel(String key, Type service, Type classType, IDictionary extendedProperties)
at Castle.MicroKernel.Handlers.DefaultGenericHandler.GetSubHandler(CreationContext context, Type genericType)
at Castle.MicroKernel.Handlers.DefaultGenericHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)

正如您从堆栈跟踪中看到的那样,它似乎又在“构建模型”(调用 DefaultComponentModelBuilder)。

我是否错误地注册了我的组件?

我已经下载了一些源代码来尝试找出我做错了什么,但想知道这是否真的是通用和远程处理的组合引起的问题?

异常是由 CaSTLe.Facilities.Remoting.RemotingInspector 试图将属性添加到已经存在的 ExtendedProperties 字典引起的。在 CaSTLe.MicroKernel.Handlers.DefaultGenericHander 中,它似乎没有检测到模型已经存在的事实(是我还是没有实际添加到字典 type2SubHandler?).

谁能告诉我我做错了什么,或者真的有错误吗?

最佳答案

我谦虚的建议是,这根本不是温莎城堡的问题。可能您在 CaSTLe Windsor 尝试解析哪个字典(或其他具有唯一键约束的集合)具有重复键的组件中定义了一个静态字典。可能来自复制粘贴操作。如果您尝试手动实例化该类,则会出现此错误。代码可能如下所示:

public class MissTypedDictionaryClass
{
... some ctors here
... some other methods and props

... and somewhere here lies the mistyped dict
private static readonly Dictionary<string, string> MyDeclaredDict = new Dictionary<string, string>()
{
{"Key1", "Val1"},
{"Key2", "Val2"},
{"Key1", "Val3"}, // Here is the problem.
};
}

关于caSTLe-windsor - 远程通用组件的异常 "an item with the same key has already been added",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9132283/

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