I have:
var someConcreteInstance = new Dictionary<string, Dictionary<string, bool>>();
and I want to pass it to the interface version, that is:
someInterfaceInstance = (IDictionary<string, IDictionary<string, bool>>)someConcreteInstance;
'someInterfaceInstance' is publicly available:
IDictionary<string, IDictionary<string, bool>> someInterfaceInstance { get; set; }
It compiles correctly, but throws an execution cast error.
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.Dictionary`2[System.String,System.Boolean]]' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Collections.Generic.IDictionary`2[System.String,System.Boolean]]'.
What am I missing? (Problems with a nested generic type / Property?)
dictionary generics casting c # nested
nicodemus13
source share