Hi all,
I have encountered a small problem when trying to resolve an interface in castle using reflection.
Lets say I have an interface IService
, and can resolve it like this:
var service = wc.Resolve<IService>();
This works as expected, but I want to call the method through reflection and can do so like this:
MethodInfo method = typeof(WindsorContainer).GetMethod("Resolve",new Type[] {});
MethodInfo generic = method.MakeGenericMethod(typeof(IService));
var service = generic.Invoke(wc,new object[]{});
This also works fine. Now lets imagine I want to select the type to be reloved using reflection.
Type selectedType = assembly.GetType("myProject.IService")
And then try to invoke it like this:
MethodInfo method = typeof(WindsorContainer).GetMethod("Resolve",new Type[] {});
MethodInfo generic = method.MakeGenericMethod(selectedType);
var service = generic.Invoke(wc,new object[]{});
I get a Castle error:
"No component for supporting the service myProject.IService was found"
The Type of selectedType appears to be correct, but there is a problem.
Does anyone know what I can do to invoke the resolve method correctly?
BTW MakeGenericMethod(typeof(selectedType)
does not compile.
Thanks in advance