Dictionary and Items protected members of a KeyedCollection in 5.3.1?

Hello,

I’ve been using Unity 5 for a year and everything worked fine until last week when we had the idea to update our IDE to 5.3.1 version.

Now the compiler shows two errors:

The name `Dictionary' does not exist in the current context.
The name `Items' does not exist in the current context.

both localized in a simple KeyedCollection

public class CommandProcessQueueCollection : KeyedCollection<int, CommandProcessQueue>
{
       public bool TryGetQueue(int id, out CommandProcessQueue queue)
            {
                if (Dictionary != null)
                {
                    return Dictionary.TryGetValue(id, out queue);
                }
    
                foreach (var i in Items)
                {
                    var k = GetKeyForItem(i);
                    if (Comparer.Equals(id, k))
                    {
                        queue = i;
                        return true;
                    }
                }
                queue = default(CommandProcessQueue);
    
                return false;
            }
}

Do you have any idea about this odd issue?

Thank you very much for your support.

G

Update:

Things are becoming even more tricky as the exact same code has been compiled in 5 different machines with 5.3.1 installed.

Well, 2 out of 5 proved to compile without any error.

Furthermore, msbuild seems to compile the code without any error as well.

Probably, there are differences, among the machines, in the .NetFramework used by Mono for compilations.

Now first of all I’m surprised how it doesn’t ask you to implement KeyedCollection’s abstract methods.

I did a small test on my machine, it appears that Items of KeyedCollection is not exposed in the api, which is why this error appears. Might be a bug.

I bet you are adding the using System.Collections.ObjectModel to insure that you can construct a class that inherits from KeyedCollection? Are you?

BTW when using more abstract classes from the c# api, I suggest you increase the compatibility level: In the editor go to Edit > Project Settings > Player and under “Other” tab, find “Optimisation” and select “.Net 2.0” from the API compatibility drop-down list. If you haven’t done so already. It unlocks more of the .Net api functionality.

Maybe you should find another way around for now.

Cheers!