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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:42:30+00:00 2026-05-28T06:42:30+00:00

I am looking at a class in a solution that implements the ISerializable interface.

  • 0

I am looking at a class in a solution that implements the ISerializable interface. It has a GetObjectData method for serialization as required by the interface. There is not any custom serialization happening here, it is simply populating the SerializationInfo object with the names of the properties of the class and their values.

[Serializable]
public class PersonName :ISerializable
{
    [DataMember]
    public string NamePrefix { get; set; }
    [DataMember]
    public string GivenName { get; set; }
    [DataMember]
    public string SurName { get; set; }

    public PersonName(string givenName, string surName, string namePrefix)
    {
        GivenName = givenName;
        SurName = surName;
        NamePrefix = namePrefix;
    }

    public PersonName()
    {
    }

    #region ISerializable Members

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("NamePrefix",NamePrefix);
        info.AddValue("GivenName",GivenName);
        info.AddValue("SurName",SurName);
    }
}

From the documentation I’ve read so far, as I understand it, this is what would happen anyway by the class being marked with the [Serializable] attribute, and as you can see the class does not have a deserialization constructor, which is why I’m looking at it to begin with. From what I can tell, rather than needing to add the deserialization constructor to the class, the class really doesn’t need to implement the ISerializable interface in the first place. Is that correct?

  • 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-28T06:42:30+00:00Added an answer on May 28, 2026 at 6:42 am

    It’s pretty pointless.

    It could be justified if it had once implemented ISerializable for a better reason, and implementation changes meant that it was no longer as useful. It could be a breaking change to stop implementing it.

    If they’d implemented it with an explicit implementation (void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) rather than public void GetObjectData(SerializationInfo info, StreamingContext context) and had the constructor that took SerializationInfo and StreamingContext private, then it’d be a less damaging change – still technically a breaking change but much less likely to actually break any real uses. This in itself is a reason for having that constructor private.

    It must though be at least protected if the class isn’t sealed, and derived classes must use it if they are to also be serialisable. In this case it’s totally going to be a breaking change to stop using it as all derived classes would then be broken.

    It would likewise be breaking change if you didn’t implement it, and then started doing so, and had classes derived from it. This could be a justification for pre-empting the possibility, though to be honest I’d see that as a major failure of the YAGNI principle unless there was a very very good reason to suspect it would become useful. (Generally if you were going to add something that would make it necessary you could wrap whatever features required it in another class, implement it on that, and have a member of that type, so the existing class can still be serialised without it).

    Edit: The “must” above is the “must” of “you must do this or there are bad implications” rather than the “must” of “you must do this or it won’t compile”. Of course, the former are worse than the latter because you can sometimes fail to do them.

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

Sidebar

Related Questions

I am looking for a class or method that takes a long string of
I was looking for some utility class/code that would take a java bean and
I'm looking for a good PHP login class via MySQL, and I'm not yet
I have a third party api, which has a class that returns an enumerator
I'm interested to know if there is an interface that I can use to
I have a class that inherits from a base class and implements the following...
Are there any classes (free, open source or commercial) that perform access control similar
I'm using NHibernate and looking for a solution that will allow me to audit
Looking for C# class which wraps calls to do the following: read and write
I'm looking for the class name of the popup/message windows on the iPhone (it's

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.