views:

60

answers:

1

At my level of experience with Unity it might be faster to ask whether the "generics handling" bug acknowledged by ctavares back in 2008 was fixed in a public release.

Here was the problem (which might be my problem today):

Hi,

I get an exception when using ....

container.RegisterType(typeof(IDictionary<,>), typeof(Dictionary<,>));

The exception is...

"Resolution of the dependency failed, type = \"IDictionary2\", name = \"\". Exception message is: The current build operation (build key Build Key[System.Collections.Generic.Dictionary2[System.String,System.String], null]) failed: The current build operation (build key Build Key[System.Collections.Generic.Dictionary2[System.String,System.String], null]) failed: The type Dictionary2 has multiple constructors of length 2. Unable to disambiguate.

When I attempt...

IDictionary myExampleDictionary = container.Resolve>();

Here was the moderated response:

There are no books that'll help, Unity is a little too new for publishers to have caught up yet.

Unfortunately, you've run into a bug in our generics handling. This is currently fixed in our internal version, but it'll be a little while before we can get the bits out. In the meantime, as a workaround you could do something like this instead:

public class WorkaroundDictionary : Dictionary { public WorkaroundDictionary() { } }

container.RegisterType(typeof(IDictionary<,>),typeof(WorkaroundDictionary<,>));

The WorkaroundDictionary only has the default constructor so it'll inject no problem. Since the rest of your app is written in terms of IDictionary, when we get the fixed version done you can just replace the registration with the real Dictionary class, throw out the workaround, and everything will still just work.

Sorry about the bug, it'll be fixed soon!

+1  A: 

According to the Unity Team:

Just wanted to let folks know we've released the bits that have the generics fixes in them. Take a look and let us know what you think. It's checked into codeplex source control.

You may need to get the latest source and build yourself (2.x) as the bug fix may not have been packaged yet.

Tom Anderson
When I run container.`RegisterType(typeof(IDictionary<,>), typeof(Dictionary<,>));` I do *not* get an exception. This must mean the bug is fixed! Wow, why did I ask the question in the first place? [Mean-spirited sarcasm here until actual question is dignified with an answer.]
rasx
I am not exactly sure what else you are expecting. The unity team says that the bug was fixed in the source, i suggested that if you are still seeing it to get the latest source and see if it still exists.
Tom Anderson