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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:47:58+00:00 2026-05-26T22:47:58+00:00

Lets say, I have a class with objects in it. namespace Class_Serialization { [Serializable]

  • 0

Lets say, I have a class with objects in it.

namespace Class_Serialization
{
    [Serializable]
    public class Data
    {
        public string Name = "Example1";
        public string place = "Torino";
        public DateTime time = DateTime.Now;
    }
}

I am trying to serialize it using ISerialization interface

[Serializable]
public class SerializeThisClass : ISerializable
{
    public Data StreamThisData;

    public SerializeThisClass()
    {

    }

    public SerializeThisClass(Data _StreamThisData)
    {
        StreamThisData = _StreamThisData;
    }
    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
    void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("Object Data", StreamThisData);
    }
}

Now, When I serialize with the code below

Data DataToSerialize = new Data();
BinaryFormatter DataToBinary = new BinaryFormatter();
SerializeThisClass serialize = new SerializeThisClass(DataToSerialize);
SerializeIn SerializeInMem = new SerializeIn();
DataToBinary.Serialize(SerializeInMem.StreamOfData, serialize);
ListOfStreams.Add(SerializeInMem);

It serializes normally, but when I try to deserialize it, it gives me error

BinaryFormatter BinaryToData = new BinaryFormatter();
foreach (SerializeIn x in ListOfStreams)
{
    x.StreamOfData.Position = 0;
    SerializeThisClass DeserializeData = (SerializeThisClass)BinaryToData.Deserialize(x.StreamOfData);
    MessageBox.Show("Name: " + DeserializeData.StreamThisData.Name + "\nPlace: " + DeserializeData.StreamThisData.place + "\nDateTime: " + DeserializeData.StreamThisData.time.ToString());
}

Error: $exception{“The constructor to deserialize an object of type
‘Class_Serialization.SerializeThisClass’ was not found.”}
System.Exception {System.Runtime.Serialization.SerializationException}

  • 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-26T22:47:59+00:00Added an answer on May 26, 2026 at 10:47 pm

    If you are implementing ISerializable, you need a constructor of the signature:

    protected YourType(SerializationInfo information, StreamingContext context) {}
    

    which loads the data (basically, the reverse of GetObjectData). Presumably, with (untested):

    StreamThisData = (Data)info.GetValue("Object Data", typeof(Data));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have an object class Person { public string Name { get;
Let's say we have a collection of Person objects class Person { public string
Lets say I have this class in foobar-shared.lib: class FooBar { std::string m_helloWorld; }
Lets say I have the following code: public class Base { // Some stuff
Lets say I have these classes: class Foo { public $_data; public function addObject($obj)
I have two objects that are derived from same the base class. Lets say
Lets say I have a class that is doing something like: public class Foo
Lets say i have a class like this class book { public $title; public
Let's say I have created two objects from class foo and now want to
Let's say we have a concrete class Apple . (Apple objects can be instantiated.)

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.