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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:33:28+00:00 2026-05-24T07:33:28+00:00

I have an object that is deserialized with this: public object DeSerializeObject(string filename) {

  • 0

I have an object that is deserialized with this:

public object DeSerializeObject(string filename)
        {
            object objectToSerialize;
            Stream stream = File.Open(filename, FileMode.Open);
            BinaryFormatter bFormatter = new BinaryFormatter();
            objectToSerialize = (object)bFormatter.Deserialize(stream);
            stream.Close();
            return objectToSerialize;
        }

    public GUI_Settings(SerializationInfo info, StreamingContext ctxt)
    {
        PrinterFont = (Font)info.GetValue("_printFont", typeof(Font));
    }

How could I pass in and object as I deserialize it? Kind of like this

public object DeSerializeObject(string filename, someObject thing)
            {
                ......
                objectToSerialize = (object)bFormatter.Deserialize(stream, thing);
                .....
            }

public GUI_Settings(SerializationInfo info, StreamingContext ctxt, someObject thing)
        {

            PrinterFont = (Font)info.GetValue("_printFont", typeof(Font));
            _thing = thing;
        }

I’m not quite sure if I explained it clearly let me try again.

Inside of my main class I say

_settings = (GUI_Settings)new ObjectSerializing()
    .DeSerializeObject("Settings.data");

or if I understand what Jalal Aldeen Saa’d said

_settings = (GUI_Settings)ObjectSerializing
    .DeserializeFromFile<GUI_Settings>("Settings.data");

When the code runs I need to send it a reference to _backend type backEndInitializer. This reference is held within this main class. GUI_Settings is the type that I am deserializing. _backend is the reference that I need to send the GUI_Settings() method to use.


Answer:

public static object DeSerializeObject(string filename, backEndInitializer backend)
    {
    object state = backend; // your object

    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bFormatter =
        new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(
            null,
            new System.Runtime.Serialization.StreamingContext(
                System.Runtime.Serialization.StreamingContextStates.All,
                state)); // pass it in

    object objectToSerialize;
    Stream stream = File.Open(filename, FileMode.Open);
    //BinaryFormatter bFormatter = new BinaryFormatter();
    objectToSerialize = (object)bFormatter.Deserialize(stream);
    stream.Close();
    return objectToSerialize;
}

Then in the class that is being deserialized

public GUI_Settings(SerializationInfo info, StreamingContext ctxt)
        {
            _backend = (backEndInitializer) ctxt.Context;
}
  • 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-24T07:33:30+00:00Added an answer on May 24, 2026 at 7:33 am
            object state = null; // your object
    
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = 
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(
                    null, 
                    new System.Runtime.Serialization.StreamingContext(
                        System.Runtime.Serialization.StreamingContextStates.All, 
                        state)); // pass it in
    

    From there you can access it object in the context argument in your deserialization constructor. The StreamingContext will have a reference to this instance

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

Sidebar

Related Questions

I have an object that starts a thread, opens a file, and waits for
I have an object that can build itself from an XML string, and write
I have an object that is generated in one class public class CreatingClass {
I have a simple class in asp.net mvc that looks like this: public class
I have this xml snippet as part of a xml file that will be
I have a Json file that looks like this: [ { field:val }, ....
I have a simple object that is deserialized from JSON into a server-side object.
I'm trying to build an object that looks something like this: public class MyObject
I have an object that contains public class PositionsChannelApplicationGroups { public PositionsChannelApplicationGroups(){} private Map<MyObj1,
I have a class that looks like this: public class Person { public class

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.