Last post Jun 24, 2014 07:00 PM by Xequence
Jun 20, 2014 05:37 PM|xequence|LINK
I register a single component at run time so my object is able to be used. The problem is, I need to remove this component once I use it, because it will be a different component entirely coming in to be consumed. Here is the code. Keep in mind, once I return
consumers, I should be able to dispose this correctly and allow myself to register a new component in this list. Has anyone had problems with this, trying to register a component, but only 1 can exist? The method in question is Add<T> because T is what is
coming in and fails on the foreach statement because the previous component still exists...
public class EventSubscriptions : ISubscriptionService, IDisposable
private static readonly WindsorContainer IoC = new WindsorContainer();
// Flag: Has Dispose already been called?
bool disposed = false;
public static void Add<T>()
var consumerType = typeof(T);
var items = consumerType.GetInterfaces()
.Where(x => x.IsGenericType)
.Where(x => x.GetGenericTypeDefinition() == typeof(IConsumer<>))
foreach (var item in items)
public IEnumerable<IConsumer<T>> GetSubscriptions<T>()
var consumers = IoC.ResolveAll(typeof(IConsumer<T>));
public void Dispose()
// Dispose of unmanaged resources.
// Suppress finalization.
// Protected implementation of Dispose pattern.
protected virtual void Dispose(bool disposing)
// Free any other managed objects here.
// Free any unmanaged objects here.
disposed = true;
An exception of type 'Castle.MicroKernel.ComponentRegistrationException' occurred in Castle.Windsor.dll but was not handled in user code
Additional information: Component xxx.xxx.xxx.ApproveDocument could not be registered. There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.
Jun 24, 2014 02:58 AM|Kevin Shen - MSFT|LINK
For your problem,I think when your dispose object for your ioc container,I guess It just release the instance of unmanaged object,but it didn't remove the components in your Ioc Container.
So when you try to add new component which in fact was registered in your container before.it will occur the
Component xxx.xxx.xxx.ApproveDocument could not be registered. There is already a component with that name.
So I suggest that you should remove component in castle windsor.
For I am not sure which castle version you are using
If Prior to 3.0 version,you can do like below:
After version 3.0 ,we can not do this ,because there is no RemoveComponent in version 3.0
Here is a article which provide a method how to remove the component in version 3.0
Please refer to the link below:
Jun 24, 2014 07:00 PM|xequence|LINK
I will try this http://ialekseev.blogspot.it/2012/10/how-to-remove-component-in-castle.html and let you know if this works for me. Thank you.
Does it help that I can only have 1 component registered to succeed?