I normally register components using (fluent) code but I now have a requirement to register certain types via XML. The file looks like this:-
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<components>
<component service="MyNamespace.IFoo, MyAssembly"
type="MyNamespace2.ConcreteFoo, MyAssembly2"
lifestyle="transient" />
</components>
</configuration>
And I use the following code to register the types:-
container.Install(
Castle.Windsor.Installer.Configuration.FromXmlFile(filename));
However this falls over with a Castle.MicroKernel.SubSystems.Conversion.ConverterException
:-
Could not convert string 'MyNamespace2.ConcreteFoo, MyAssembly2' to a type. Assembly MyAssembly2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null was matched, but it doesn't contain the type. Make sure that the type name was not mistyped.
To make sure I wasn't going mad I added this code just before the above line:-
var test = AppDomain.CurrentDomain.GetAssemblies();
A breakpoint confirms that the assembly in question is in the current AppDomain, and the concrete type in question is in this assembly's 'DefinedTypes'. It's also public.
This should be a straightforward thing to do, but I'm scratching my head now!
Edit
I should point out that the assembly containing the concrete type is loaded at runtime (using MEF), and exists in a different folder to the application's exe (so I can't use <using>
in my XML file). However I had assumed that as it's present in the AppDomain then what I'm doing should work. Or is Windsor doing something strange like trying to load the assembly from file again, rather than just looking in the AppDomain?
Edit 2
As an experiment I've just tried this line of code:-
container.Register(Classes.FromAssemblyNamed("MyAssembly2").BasedOn<IFoo>());
This throws a FileNotFoundException, backing up my earlier hunch that Windsor is trying to load the assembly from file rather than checking in the AppDomain. Why is this?