Published by breki on 24 Aug 2010 at 06:43 am
Windsor Castle: Strange Resolving Behavior
A user reported a bug in Maperitive – it throws
Castle.MicroKernel.Resolvers.DependencyResolverException: Could not resolve non-optional dependency for ‘Karta.DataSources.OsmFileMapDataSource’ (Karta.DataSources.OsmFileMapDataSource). Parameter ‘fileName’ type ‘System.String’
I tried to reproduce this behavior using a simple unit test, but I couldn’t, so I’m posting the actual code. This is where the exception occurs:
return windsorContainer.Resolve<OsmFileMapDataSource>();
And this is how OsmFileMapDataSource constructors look like:
public OsmFileMapDataSource(
string fileName,
IFileSystem fileSystem,
IMapDataLayerFactory layerFactory)
{
...
}
public OsmFileMapDataSource(IMapDataLayerFactory layerFactory)
{
...
}
Needless to say, both IFileSystem and IMapDataLayerFactory are registered in the container (IMapDataLayerFactory is registered as a typed factory, by the way). OsmFileMapDataSource is also registered as an implementation of itself. And I’m using version 2.1.0.6655 of the library.
What’s strange about this is that if I move the second constructor in front of the first one, the component is resolved without problems. I’m not sure if this is intended behavior, but I doubt the order of constructors should be a determining factor on how components are resolved.
But as I said, I couldn’t reproduce this behavior using a simplified test code, so I guess I should start debugging it instead.


Krzysztof Ko?mic on 24 Aug 2010 at 8:13 #
It’s a known issue IoC-168 which has been fixed in version 2.5
changing the order of the .ctors in the code changes how C# compiler puts them in metadata of the assembly, which changes how reflection returns them.
It’s quite obscure, but the important piece is – it’s fixed now.
breki on 24 Aug 2010 at 9:29 #
@Krzysztof,
Great to hear, as I’m in the middle of downloading v2.5
. I’ve decided to test it out with the new version instead of debugging it.
I’m still puzzled with the fact that I cannot reproduce this scenario cleanly, though.
breki on 24 Aug 2010 at 13:48 #
@Krzysztof,
Unfortunately the situation is exactly the same with the newest version of Windsor. I’ll need to do some debugging after all…