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.
Thank you for this!!! This was the answer I needed. I know it's been almost a year since you posted it, but it was exactly the answer I needed!ReplyDelete
Like the guy before me, almost a year but I had the same issues trying to put SerializableDictionary by http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspxReplyDelete
I'm trying to remember why I wanted to drop a dictionary object into viewstate in the first place. Adding stuff to a page's viewstate means extra data to transport from server to client and back again so dropping in a fully-loaded dictionary might not be a great idea.ReplyDelete
This is a situation of supporting an existing implementation unfortunately, reworking it is more time as you most likely can guess. I do agree with you on that one.ReplyDelete
thank you! you helped me :DReplyDelete
Thank you very much! You helped me with this article.ReplyDelete