Reputation: 10193
I have implemented an interface-based typed factory, which gets registered like this:
container.Register(Component.For<ITypedFactoryComponentSelector>().ImplementedBy<CustomTypedFactoryComponentSelector>());
container.Register(Component.For<IComponentFactory>().AsFactory(c => c.SelectedWith<CustomTypedFactoryComponentSelector>()));
IComponentFactory
looks like this:
public interface IComponentFactory
{
T Resolve<T>();
T GetByName<T>(string name);
void Release(object component);
}
While CustomTypedFactoryComponentSelector
looks like this:
public class CustomTypedFactoryComponentSelector : DefaultTypedFactoryComponentSelector
{
protected override string GetComponentName(MethodInfo method, object[] arguments)
{
if (method.Name == "GetByName" && arguments.Length == 1 && arguments[0] is string)
return (string)arguments[0];
return base.GetComponentName(method, arguments);
}
It's essentially a service locator that allows me to resolve components like this:
var foobar = _componentFactory.Resolve<IFoobar>();
This mechanism has been in use for many years, but over the past year I've been randomly seeing the following InvalidOperationException:
Can't find information about factory method <<fully qualified name of IFoobar interface I'm trying to resolve>> Resolve[IFoobar]. This is most likely a bug. Please report it. at Castle.Facilities.TypedFactory.Internal.TypedFactoryInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.IComponentFactoryProxy.ResolveT
It's not the same component every time - I've just used 'IFoobar' for example purposes.
It's hard to say when it started, but it might have coincided with upgrading the app from .Net Framework 4.x to .Net 6. It's a WPF desktop app by the way.
The exception has been happening with a few versions of Windsor including the latest (v6.0.0, and Core to 5.1.1). It seems to occur a short time after I've stopped at a breakpoint then resumed execution, and am not aware of it happening during "normal" running of the app. Any thoughts? It's more of an annoyance really, but it's always at the back of my mind that something isn't quite right with some aspect of Windsor.
Upvotes: 0
Views: 13