Did the Unity Team fix that "generics handling" bug back in 2008?

Posted by rasx on Stack Overflow See other posts from Stack Overflow or by rasx
Published on 2010-04-18T17:06:47Z Indexed on 2010/04/18 17:13 UTC
Read the original article Hit count: 333

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about unity

Related posts about c#