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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:37:33+00:00 2026-06-18T07:37:33+00:00

The title is a bit confusing, hopefully someone maybe know’s a better fitting title

  • 0

The title is a bit confusing, hopefully someone maybe know’s a better fitting title for my problem.

I am trying to create a class which derives from Collection<Classname> to implement an easy way to save and loading Configuration files. Writing to file is no problem, but I am not able to implement the deserialze function. I am unsure how to assign the deserialized content back to my instance.

Current approach:

[DataContract(Name = "Configurations", Namespace = "")]
public class Configurations : Collection<Configuration>
{
    internal void SerializeToBinaryFile(string path)
    {
        Helper.DumpObjectToBinaryFile(this, path);
    }

    internal void DeserializeFromBinaryFile(string path)
    {
       // Getting Error:
       // This expression can not be used as an assignment target
       this = Helper.GetObjectFromBinaryFile<Collection<Configuration>>(path);
    }
}

I am familiar with this.Add([Configuration]) but this just gives the opportunity to insert one item. I thought about using a foreach(Configuration c in temporaryObject and add them one by one but this can’t be the best solution.

Thanks for any hint!

Edit 1:

I’ve added the foreach iteration for adding the Configurations

    internal void DeserializeFromBinaryFile(string path)
    {
        foreach (var c in Helper.GetObjectFromBinaryFile<Collection<Configuration>>(path))
        {
            Add(c);
        }
    }

This seems to work fine. Does someone know a better pattern?

  • 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-18T07:37:34+00:00Added an answer on June 18, 2026 at 7:37 am

    You cannot assign to new instance of class to “this” regardless if you are doing de-serialization or something else. Code bellow just uses new constructor and doesn’t work either. Basically, you do have different 2 instances of class in memory at that point.

    public class Point
    {
        public int X { get; set; }
        public int Y { get; set; }
    
        public void CreatePoint(int x, int y)
        {
            // Doesn't work either
            this = new Point();
        }
    }
    

    You have to do this outside of the body of the class, so rather make static deserialization method:

    [DataContract(Name = "Configurations", Namespace = "")]
    public class Configurations : Collection<Configuration>
    {
        internal void SerializeToBinaryFile(string path)
        {
            Helper.DumpObjectToBinaryFile(this, path);
        }
    
        internal static Configurations DeserializeFromBinaryFile(string path)
        {
            return Helper.GetObjectFromBinaryFile<Collection<Configuration>>(path);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I know the title is a bit confusing but here is my problem:
I know the title of this question is a bit confusing, but here it
I know the title sound confusing and thats because it is. its a bit
My title is a bit confusing, but I'm trying to write a loop that
So I know I butchered the title a bit but if someone looks here
The title is a bit confusing, I know, but it's the best I could
I know the title is bit confusing for my question. Let me explain:- There
I know the title is bit confusing for my question. Let me explain:- There
I know the title is a bit confusing but here's my situation #!/bin/bash for
Maybe my title is a little bit confusing so I'll illustrate with a scenario

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.