The problem you are describing is the fundamental principle of generics.
ICollection<Object> not the base class of ICollection<String> , even if String is a child of the Object class. This is done at compile time, so you basically get two different definitions of the ICollection class. Therefore, they cannot be cast. (SO smart people, please feel free to correct me for any inaccuracies)
In MVC3, I worked on this by doing the following:
class Container{ } class Container<T> : Container{ T Data {get;set;} }
Then in your opinion
@model Container
If you need only ordinary material, not knowing the general type.
@model Container<SomeDataType>
If you need data of type type.
Use Case:
I am creating a ModelContainer class that stores my model internally, along with an array of error messages that may render the page in partial. Since the partial part can be used on every page, it does not know what the Generic type will be, so this workaround is necessary.
This cannot be used if you are trying to access shared data without knowing its type. Hope this solves your problem.
Daryl teo
source share