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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:11:03+00:00 2026-06-13T08:11:03+00:00

I do not think this is a duplicate. I have done some reading but

  • 0

I do not think this is a duplicate. I have done some reading but did not find anything the same as this. It seems that fields can be serialized in binary formatters and in protobuf but not in XML. I don’t know about JSON.

I am looking at replacing the standard .NET binary serializer with protobuf-net. The reason is to improve speed and get a smaller persisted file size.

In NET Binary I just marked the classes as serializable and left it at that. Not good I suspect.

With protobuf-net I need to specify what gets serialized with the [ProtoMember()] attribute. My newbie testing shows that private fields get serialized if so marked as do auto properties.

I do not want to change the class code definitions at all since I still need to be able to deserialize the old persisted data created by the NET serializer. I have a mixture of:

  1. Private fields that get used inside the class
  2. Private fields whose value gets set in constructors
  3. Private fields that are backing fields for non automatic properties
  4. Properties with the backing fields above
  5. Auto properties
  6. Properties with no setters that return some calculation or value determined internally

and probably some others. In other words pretty much every type of field and property.

I guess I need to persist any value that represents the state of the object that cannot be constructed after deserialization from the file.

I suppose there would be no harm in persisting every field and property but that would just make the job slower and the file bigger than it needs to be.

I think I can ignore private fields that are used only inside the class and are not set from outside.
I think I should persist those fields that are set in constructors.
I am not sure about backing fields – is it better to persist them or their public property?
I must persist auto properties
I can’t persist properties with no setters so I need to persist whatever fields/properties get used in their calculations.

Am I on the right track or missing the point.

Thanks in advance.

  • 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-13T08:11:04+00:00Added an answer on June 13, 2026 at 8:11 am

    We can’t say what needs to be serialized. BinaryFormatter works on an “all fields” basis (unless they are explicitly marked not for serialization). You could use the same approach, but if you’re using automatically implemented properties (which is fine) then note that you cannot add attributes to the backing field – unlike field-like events, the following is not valid c#:

    [field:ProtoMember(1)] // not valid
    public int X { get; set; }
    

    This means that your only sensible choice is to decorate the property:

    [ProtoMember(1)]
    public int X { get; set; }
    

    Because, if you change the automatically implemented property to a regular property, you will have broken BinaryFormatter‘s deserialization, since the field-name will have changed. That’s fine, though – there’s nothing wrong with marking either the fields or the properties (or both in the same type) for serialization. Another consideration on some platforms is accessibility: a private field may be inaccessible, where-as a public field works fine. And obviously public fields are pretty uncommon.

    So:

    • decide what needs to be serialized (I can’t tell you this)
    • mark it for serialization
    • do not change anything from automatically-implemented property to a regular property if you need BinaryFormatter to keep working (protobuf-net doesn’t care if you change this)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is a simple question, but I can not find the answer
I have tried every way I can think of with this, but just not
I don't think I've seen anything that says you're not allowed to do this
I saw this question and some similar and I think it's not duplicate :
I've done some research but nothing seems to fit my needs. I have a
From reading the Weld docs I don't think this can be done, but I
This is not 100% programming related. But I think this is somewhat useful because
I am not familiar with Ivy. I think this is some utility to automatically
I've been searching for a while and everybody seems to think this is not
This is a really short question I think but I'm not sure I understand

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.