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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:24:53+00:00 2026-06-09T22:24:53+00:00

when serializing a type that has a boolean member that is inline intialized to

  • 0

when serializing a type that has a boolean member that is inline intialized to true – I always get the value as true on deserialization of the object (obviously, the problem is when the actual value of the member was false before the serialization).
this does not happen in the opposite case (inline initialized to false and object value is true – I have also tried other manipulations and other data member types and they all work just fine).

here is the type:

[ProtoContract]
public class SomeObject
{
    public SomeObject() {}

    [ProtoMember(1)]
    private bool m_SomeMember = true;

    public bool SomeMember
    {
        get { return m_SomeMember; }
        set { m_SomeMember = value; }
    }
}

here is the code:

var stream = new MemoryStream();
var data = new SomeObject() {SomeMember = false};
Serializer.SerializeWithLengthPrefix<SomeObject>(stream, data , PrefixStyle.Base128);
stream.Position = 0;
var deserializedObject = Serializer.DeserializeWithLengthPrefix<SomeObject>(stream, PrefixStyle.Base128);

while looking at the values of the deserializied object – the SomeMember value is true.
this doesn’t make much sense, since the inline members initialization code should be inserted into the default ctor by the compiler – and as far as I understand protobuf should set values of members only after the ctor is being called (don’t think it is possible otherwise) so, HELP? (Marc?)

  • 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-09T22:24:54+00:00Added an answer on June 9, 2026 at 10:24 pm

    By default, protobuf-net uses implicit zero defaults (and false is considered a zero). You can tell it what you mean:

    [ProtoMember(1), DefaultValue(true)]
    private bool m_SomeMember = true;
    

    or you can (via RuntimeTypeModel.UseImplicitZeroDefaults) disable this behaviour, so that only explicit defaults are processed.

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

Sidebar

Related Questions

I get A circular reference was detected while serializing an object of type T
I want to XML-Serialize a complex type (class), that has a property of type
Certainly there is some type of context switching, marshaling, serializing, etc that takes place
I'm serializing data from my Django model into json and placing that info in
I am serializing/pickling an object, encoding it as a compressed string, and passing it
I need to avoid serializing an Event class member because when the event is
I have a LINQ to SQL entity that I will be serializing and returning
Let's say we have a template class Area , which has a member variable
I am having an issue serializing a c# class to an XML file that
I am serializing alot of arrays in php that are to be stored in

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.