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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:43:47+00:00 2026-05-18T08:43:47+00:00

Is there any way to save an entire class definition for a C# object

  • 0

Is there any way to save an entire class definition for a C# object to a file / data store?

I use the [Serializable] tag and ISerializable interface to do this already, but both of these rely on the object definition being in the assembly at run time.

What I’m looking for is a solution to the following scenario:

1) User creates object MyClass in my software and saves it

For the purpose of this example, MyClass is a stand-alone object that doesn’t rely on any other class in the system:

i.e. this could be the entire definition:

public class MyClass
{
    public int MyProperty { get; set; }
    public void DoSomething() { /* do something, like Console.Write(""); */ }
}

2) We release a patch that removes MyClass from the system

3) User loads the saved MyClass from step 1 and calls DoSomething() on it – and has the function work exactly the same as it did before the patch removed the class from the system


Is there any way this can be done without reflection / emit trickery?

  • 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-18T08:43:47+00:00Added an answer on May 18, 2026 at 8:43 am

    No, this won’t work without emitting the type definition. What you are trying to do is actually save off the code (otherwise, how would DoSomething work?) – which is what the compiler does for you. Plain serialization will never work for you here.

    So, if you need to save behavior as well as state, you need to either keep the historical code around, use some type of reflection emit trickery to persist the type definition as a loadable assembly, or use dynamic programming tricks that treat data as executable code.

    When I have had do versioned serialization before, I normally have custom serialization logic and a “version” attribute on the object – using this I can create a type that I’ve moved and renamed – say SomeClass to Archive.SomeClassV3. You can use Version Tolerant Serialization for this, but I prefer to implement ISerializable and use serialization proxies if this is required. (Well, actually I prefer to avoid this problem altogether!)

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

Sidebar

Related Questions

Is there any way to take the video feed from the camera of an
Is there any way for me to download the iOS 4.0.1 SDK without actually
is there any way of going through all the new/modified entities and setting their,
I want to download a PDF file from my server and save it to
I have a portable executable that saves data to a file in the same
First of all, thank you very much in advance for any attempt at helping
I am used to post my ideas on one forum and started to worry
I am working on an application where i am saving the state of an
I'm making word frequency tables with R and the preferred output format would be
Assume I have generic list L of some type in c#. Then, using linq,

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.