The System.Collections.Generic.Dictionary class defines a constructor used to restore the Dictionary's internal data during the deserialisation process:
"Initializes a new instance of the Dictionary class with serialized data."
protected Dictionary (
Constructors are not inherited in C# so a wrapper class must explicitly define this constructor and pass the data back up the inheritance hierarchy to the base Dictionary class:
public class CustomCollection : Dictionary
protected CustomCollection (
) : base (info, context)
// no implementation
Depending on how you construct your wrapper class, you'll most likely want to define additional constructors as well or the default (empty) constructor at a minimum as it will no longer be injected by the compiler with the deserialisation constructor present.
Without this constructor, I was receiving a corrupted ViewState exception
The state information is invalid for this page and might be corrupted.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.