I'm storing a collection of List<KeyValuePair<string, bool>>
in ViewState, the problem occurs when i'm trying to cast it back to List<KeyValuePair<string, bool>>
Error states
Unable to cast object of type 'System.Collections.Generic.Dictionary
2[System.String,System.Boolean]' to type 'System.Collections.Generic.List
1[System.Collections.Generic.KeyValuePair`2[System.String,System.Boolean]]'.
So how can convert my key value list back from the ViewState ?
My code line is:
List<KeyValuePair<string, bool>> myObject = (List<KeyValuePair<string, bool>>)ViewState["listOutputWords"];
Try this:-
As clearly mentioned by the compiler, your ViewState is holding a generic
Dictionary
ofString,Bool
but you are trying to cast it to List of Dictionary which is wrong.