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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:47:49+00:00 2026-05-22T18:47:49+00:00

I need to make a class Serializable. In this class I have a MyGuid

  • 0

I need to make a class Serializable.
In this class I have a MyGuid readonly property, that I want to be serializable but not deserializable (property is initialized in a backing field).
Using base serialization .NET features, you know, have a reandonly property make deserialization fail, ’cause it cannot deserialize a readonly property.
So I decide to create a public get-set MyGuid property with a backing field, and make setter do nothing:

[Serializable]
public class Task : ITask
{
    private readonly Guid m_guid = Guid.NewGuid();
    public MyGuid Guid
    {
        get { return m_guid; }
        set { /*Empty setter!*/ }
    }
}

Now I don’t want to shoot in my foot…
There’s a way I can make setter of MyGuid property as “deprecable” or “disabled”?
It would be nice have Visual Studio warning me if I try to use the setter.

Or, instead, there’s a better way to manage this kind of needs?

Thank you!

Edit: Found something here: Serializing private member data I’m reading…

  • 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-22T18:47:49+00:00Added an answer on May 22, 2026 at 6:47 pm
    public Guid Guid
    {
        get { return m_guid; }
        set { if (value != null) Debugger.Log(0, "Warning", "This property has an empty setter, just for serializing purpose!"); }
    }
    

    This if you accidentally set the value yourself, you’ll get a warning in the debug window. On the other hand, you absolutely need the setter for the serializer, or otherwise the deserializer would never be able to appoint the property a value after reading it from the file! So the setter is not for you but for the serializer to function normally.

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

Sidebar

Related Questions

All I need is a way to make a property of one class only
I have a whole list of entity classes which I need to make Serializable
I need to make a 2D convex hull function for a class assignment and
I have a crystal report file I need make a tiny edit in. It
I need to make an ArrayList of ArrayLists thread safe. I also cannot have
I need to make sure that user can run only one instance of my
For example I have class to serialize [Serializable] class Person { [XmlAttribute(name)] string Name
I have a class like this : import java.io.*; import java.util.*; public class Contact_Info_Entry
Yes, the title doesn't make much sense, but here's my situation. I have two
I have a generic dispatcher that takes in parameters and then make $.ajax() As

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.