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 6331471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:04:32+00:00 2026-05-24T18:04:32+00:00

I am trying to learn to use C# serialization as a way to save

  • 0

I am trying to learn to use C# serialization as a way to save objects into files that can be reloaded back into objects.

A plain class like this that I tested

[Serializable()]
public class PlainClass
{
    public string Name;
    private int Age;
    protected decimal Price;
}

Can be directly BinaryFormatter.Serialize() and BinaryFormatter.Deserialize() without errors. (by the way, the private and protected properties also get serialized although the docs say only public)

But the moment it implements ISerialization or inherit some class like Hashtable that implements ISerialization, the you-know-what deserialization constructor is required. The word or concept of “implement” becomes a misnomer because Hashtable does not actually implement that constructor.

Is there a way to fall back to the “auto” Serialization/Deserialzation provided only by the attribute? Or is there an easier way to write info.GetValue() for a hundred properties in a class?

  • 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-05-24T18:04:33+00:00Added an answer on May 24, 2026 at 6:04 pm

    There is a lot of confusion in your post:

    by the way, the prive and protected properties also get serialized although the docs say only public)

    I suspect you are confusing two different serializers; BinaryFormatter is and always has been documented as field-centric. It doesn’t distinguish between public/private, and it never looks at properties: only fields. XmlSerializer, by contrast, only looks at public properties and fields.

    The word or concept of “implement” becomes a misnomer because Hashtable does not actually implement that constructor.

    Yes it does; it is a protected constructor:

    protected Hashtable(SerializationInfo info, StreamingContext context)
    {...}
    

    If you inherit Hashtable you can chain to this constructor:

    protected YourType(SerializationInfo info, StreamingContext context)
         : base(info, context)
    { /* your extra data */ }
    

    Note, however, that you probably shouldn’t be using Hashtable much unless you are on .NET 1.1.

    Is there a way to fall back to the “auto” Serialization/Deserialzation provided only by the attribute?

    No; none.

    Or is there an easier way to write info.GetValue() for a hundred properties in a class?

    In the case of inherited data, you could chain the base-constructor or switch to encapsulation instead of inheritance – either avoids the need to worry about data other than your own.

    Note, however, that I almost always guide against BinaryFormatter – it can be vexing, and is quirky with versioning. For every annoyance with BinaryFormatter, I use protobuf-net (I would, since I wrote it) – this generally makes serialization much more controlled (and more efficient), and includes an ISerializable hook if you really want to use BinaryFormatter (i.e. it can use BinaryFormatter as the wrapper, but with a protobuf-net payload).

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

Sidebar

Related Questions

I am trying to learn how to use MSBuild so we can use it
I'm trying to learn how to use lift. I can create project skeleton by
I am trying to learn how to use the AsyncTask class to authenticate the
I'm trying to learn to use SDL for a little game I'm writing ,
I am trying to learn and use an SDK for a vendor's product. Unfortunately,
I am trying to learn to use buffer overflow attack in Ubuntu. Unfortunately, I
I am trying to learn to use the wx packages to make GUI programs
I am trying to learn CodeIgniter to use for a shopping site, but I
I'm trying to learn how to use oop in php. I'm also fairly new
I'm trying to learn how to use actionscript over mxml for flexibility. I have

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.