For various reasons I am trying to upgrade a project from an old version of Castle to v 2.5.3 (I cannot move to v3 due to breaking changes) and am encountering an issue with a generic component that is remoted:
Container.Register(Component.For(typeof(IStore<>))
.Named("GenericStore")
.AddAttributeDescriptor("remoteserver", "RecoverableComponent")
.AddAttributeDescriptor("marshalByRefProxy", "true")
.ImplementedBy(typeof(MyStore<>)));
The component appears to register OK, but at the point I attempt to resolve:
Container.Resolve<IStore<Users>>()
I get an exception "an item with the same key has already been added" and the stack trace (shortened):
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)
As you can see from the stack trace, it appears to be "building the model" (call to DefaultComponentModelBuilder) again.
Am I registering my component incorrectly?
I've downloaded some of the source code to try and find what I am doing wrong, but wonder if it is actually an issue caused by a combination of Generic and Remoting?
The exception is caused by Castle.Facilities.Remoting.RemotingInspector trying to add properties to the ExtendedProperties dictionary that alreadt exist. In Castle.MicroKernel.Handlers.DefaultGenericHander it doesn't appear to be detecting the fact that the model already exists (is it me or is nothing ever actually added to the Dictionary type2SubHandler?).
Can anyone tell me if I am doing anything wrong, or is there actually a bug?