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

  • SEARCH
  • Home
  • 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 8296489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:01:40+00:00 2026-06-08T15:01:40+00:00

I’m new to serialization, so most likely I am missing something obvious! I have

  • 0

I’m new to serialization, so most likely I am missing something obvious!

I have a class called ResultsCollection that is a four-dimension data structure — a collection of objects that are derived from the DataSet class. Each modified DataSet holds a collection of objects derived from DataTable. The relevant bits of code are:

[Serializable]
public class ResultsCollection : CollectionBase, ISerializable
{
  // indexer
  public MyDataSet this[int index] { get { return (MyDataSet)List[index]; } }
}
[Serializable]
public class MyDataSet : DataSet, ISerializable
{
  // member variable that *overrides* the Tables property of the standard DataSet class
  public new TablesCollection Tables;
}
[Serializable]
public class TablesCollection : CollectionBase, ISerializable
{
  // indexer
  public MyDataTable this[int index] { get { return (MyDataTable)List[index]; } }
}
[Serializable]
public class MyDataTable : DataTable, ISerializable
{
  ...
}

I have implemented the ISerializable interface by including a public Serialization constructor and a public GetObjectData function, as shown here:

// ResultsCollection -- serialize all variables and also the inner list itself
public ResultsCollection(SerializationInfo info, StreamingContext ctxt) : base()
{
  _memberVariable = (bool)info.GetValue("_memberVariable", typeof(bool));
  ArrayList innerList = (ArrayList)info.GetValue("List", typeof(ArrayList));
  InnerList.AddRange(innerList);
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
  info.AddValue("_memberVariable", _memberVariable);
  info.AddValue("List", InnerList);
}

// MyDataSet -- call standard base-class (DataSet) serialization functions in addition to serializing members
public MyDataSet(SerializationInfo info, StreamingContext ctxt) : base(info, ctxt)
{
  _memberVariable = (bool)info.GetValue("_memberVariable", typeof(bool));
  Tables = (TablesCollection)info.GetValue("Tables", typeof(TablesCollection));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
  base.GetObjectData(info, ctxt);
  info.AddValue("_memberVariable", _memberVariable);
  info.AddValue("Tables", Tables);
}

// TablesCollection -- serialize all variables and also the inner list itself
public TablesCollection(SerializationInfo info, StreamingContext ctxt) : base()
{
  _memberVariable = (bool)info.GetValue("_memberVariable", typeof(bool));
  ArrayList innerList = (ArrayList)info.GetValue("List", typeof(ArrayList));
  InnerList.AddRange(innerList);
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
  info.AddValue("_memberVariable", _memberVariable);
  info.AddValue("List", InnerList);
}

// MyDataTable -- call standard base-class (DataTable) serialization functions in addition to serializing members
public MyDataSet(SerializationInfo info, StreamingContext ctxt) : base(info, ctxt)
{
  _memberVariable = (bool)info.GetValue("_memberVariable", typeof(bool));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
  base.GetObjectData(info, ctxt);
  info.AddValue("_memberVariable", _memberVariable);
}

I have a single ResultsCollection object that I want to store in ViewState, in order to retrieve it on the next post-back (hence all this trouble). For the initial request, things appear to be working: I have set break-points in the Serialization functions and the data members are indeed being serialized. However, upon deserialization, the member variables are loaded properly but the List objects are full of null members. My code crashes out when I try to retrieve the DataSetName property from the first MyDataSet object in the ResultsCollection.

  • 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-08T15:01:52+00:00Added an answer on June 8, 2026 at 3:01 pm

    It turns out that CollectionBase and ISerializable are incompatible, possibly because the InnerList property of CollectionBase is read-only. Therefore what I needed to do was to remove the ISerializable definitions from the two CollectionBase-derived classes, i.e.:

    [Serializable]
    public class ResultsCollection : CollectionBase
    {
      // indexer
      public MyDataSet this[int index] { get { return (MyDataSet)List[index]; } }
    }
    [Serializable]
    public class MyDataSet : DataSet, ISerializable
    {
      // member variable that *overrides* the Tables property of the standard DataSet class
      public new TablesCollection Tables;
    }
    [Serializable]
    public class TablesCollection : CollectionBase
    {
      // indexer
      public MyDataTable this[int index] { get { return (MyDataTable)List[index]; } }
    }
    [Serializable]
    public class MyDataTable : DataTable, ISerializable
    {
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.