c# - Cannot resolve Dictionary in Unity container -


i've stumbled upon this:

within unity container, want register idictionary<tk, tv>; assume it's idictionary<string, int>

_unitycontainer = new unitycontainer()     .registertype<idictionary<string, int>, dictionary<string, int>>(); 

but if try

var d = _unitycontainer.resolve<idictionary<string, int>>(); 

it fails resolve...

i get...

microsoft.practices.unity.resolutionfailedexception: microsoft.practices.unity.resolutionfailedexception: resolution of dependency failed, type = "system.collections.generic.idictionary`2[system.string,system.int32]", name = "(none)". exception occurred while: while resolving.

exception is: invalidoperationexception - type dictionary`2 has multiple constructors of length 2. unable disambiguate.


at time of exception, container was:

resolving system.collections.generic.dictionary2[system.string,system.int32],(none) (mapped system.collections.generic.idictionary2[system.string,system.int32], (none)) ---> system.invalidoperationexception: type dictionary`2 has multiple constructors of length 2. unable disambiguate..

so looks has found type resolve (being dictionary<string, int>) failed new up...

how come unity can't resolve type? if type

idictionary<string, int> d = new dictionary<string, int>() 

that works...

any ideas?

thanks!

very interesting find +1. seems bug in unity, see here:

http://unity.codeplex.com/thread/view.aspx?threadid=30292

you can try this:

 container.registertype<idictionary<int, string>, dictionary<int, string>>                 (new injectionconstructor()); 

that makes use default constructor, circumventing issue...


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -