An entry for the “Oh right, of course that doesn’t work” file…

I have a class called MultiValueDictionary<TKey, TValue> that implements IReadOnlyDictionary<TKey, ReadOnlyCollection<TValue>>.

So far so good. All of usual LINQ stuff works as expected.

Then I think, “Wouldn’t it nice if I could also cast that into a IReadOnlyCollection<KeyValuePair<TKey, TValue>> and get a flattened view of it”.

So I add the interface and wire up the methods as explicit implementations. It compiles cleanly and I open up my tests.

error CS1061: 'MultiValueDictionary<string, int>' does not contain a definition for 'ToList' and no accessible extension method 'ToList' accepting a first argument of type 'MultiValueDictionary<string, int>' could be found (are you missing a using directive or an assembly reference?)

What do you mean it doesn’t have a ToList method. That’s a well known extension method on IEnumerable<T>, which my class implements.

In fact, I implemented that interface twice. Once as IEnumerator<KeyValuePair<TKey, ReadOnlyCollection<TValue>>> and once as IEnumerator<KeyValuePair<TKey, TValue>>.


Well back to the drawing board.