Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:57:54+00:00 2026-06-10T20:57:54+00:00

In a webpage, I am storing a Dictionary in the ViewState : Dictionary<string, string>

  • 0

In a webpage, I am storing a Dictionary in the ViewState :

Dictionary<string, string> items = new Dictionary<string, string>();
ViewState["items"] = items;

It works great. However, for some reasons, I want to use my own class instead of using Dictionary directly :

class MyDictionary : Dictionary<string, string> 
{
   ... 
}
MyDictionary items = new MyDictionary();
ViewState["items"] = items;

It doesn’t work as expected. ASP.NET complains about the fact

MyDictionary is not marked serializable

It’s ok since class attributes are not herited. So I changed my code :

[Serializable]
class MyDictionary : Dictionary<string, string> { ... }

But if I do so, I get another error message, this time after page postback :

The state information is invalid for this page and might be corrupted.
System.Web.UI.ObjectStateFormatter.Deserialize(Stream inputStream)

If viewstate can serialize a Dictionary, why it doesn’t work for a class that inherit from it ? How to make this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:57:56+00:00Added an answer on June 10, 2026 at 8:57 pm

    You need to a deserialization constructor to your class.

    class MyDictionary : Dictionary<string, string> 
    {
       public MyDictionary (){ }
       protected MyDictionary (SerializationInfo info, 
                               StreamingContext ctx) : base(info, ctx) { }
    }
    

    If you look inside a dictionary class, it requires this to deserialize.

    protected Dictionary(SerializationInfo info, StreamingContext context);
    

    Tried it with a test page and it works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My webpage has a table where you can select different items. I want to
I have a webpage which has nothing on it except some string(s). No images,
i want to send a json string from a html webpage using javascript to
I want some random no displaying on the web page and storing it into
I have a webpage that uses some hidden textarea fields - for storing some
I've saved an entire webpage's html to a string, and now I want to
I am trying to load processed webpage into string, but seems like it is
how would i put the contents of a webpage into a string? it would
I need to read webpage and store its content in string for further processing.
This webpage opens a Google maps and a weather gif image. It works fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.