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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:58:34+00:00 2026-06-10T23:58:34+00:00

I have a complex model serialized/deserialized with protobuf-net, and we had several bugs with

  • 0

I have a complex model serialized/deserialized with protobuf-net, and we had several bugs with this “feature” of not serializing default values.

Example:

[DataContract]
class Foo{
  public Foo(){
    // Value forced by constructor
    this.Value = 1;
  }

  // Buggy, when Value is set to zero
  [DataMember(Order = 1)]
  public double Value {get; set}
}

When Value = 0, it is not serialized by protobuf-net, but during deserialization, the constructor forces Value to 1 (and protobuf-net do not change this).

In order to make it work, I need to force protobuf-net to serialize values, with:

  // Works fine
  [DataMember(Order = 1, IsRequired = true)]
  public double Value {get; set}

But, as we already got bugs because of this feature, we’d like to force protobuf-net for the whole model, instead of marking every property.

Is it possible?

  • 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-10T23:58:35+00:00Added an answer on June 10, 2026 at 11:58 pm

    Yes, this feature is fully supported. Actually, if I was forced to admit to bad design decisions in v1, the implicit-zero-defaults would be one of them – but for backwards compatibility the behaviour is retained by default. What you are looking for is RuntimeTypeModel.UseImplicitZeroDefaults, which is true by default.

    To avoid changing the behaviour of code relying on v1 behaviour (via Serilaizer.*), you cannot change this feature on the default model, so what you need to do is:

    1. define your own model/serializer-instance
    2. set UseImplicitZeroDefaults = false, before using it
    3. in your serialize/deserialize code, use this instance rather than Serializer.*

    for example:

    private static readonly RuntimeTypeModel serializer;
    static MyType() { // your type-initializer for class MyType
        serializer = TypeModel.Create();
        serializer.UseImplicitZeroDefaults = false;
    }
    ... then when needed:
    serializer.Serialize(stream, obj);
    ...
    ObjType obj = (ObjType)serializer.Deserialize(stream, null, typeof(ObjType));
    

    Another approach I could perhaps consider in the future is allowing for assembly-level attributes; this would help in particular for anyone using “precompiler” (for example, targeting mobile devices or WinRT) – so (just thinking aloud):

    // this feature ***does not currently exist***
    [assembly:ProtoDefaults(UseImplicitZeroDefaults=false, SkipConstructor=true)]
    

    which would then apply to all types in that assembly. Just a thought. Another obvious advantage is that it would work with code that uses the classic Serializer.* API.

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

Sidebar

Related Questions

I have a problem with NSUndoManager not undoing when working with a complex model.
I have a complex user model with a validation method before_validation_on_update :geocode_places This validation
I have a little complex Database model on which i am not able to
I have a fairly complex and big Model called Task . In this object
I have a fairly complex model for one of my pages; it's made of
I have a fairly complex data model and consequently a fairly complex query (using
In my model I have three complex scopes returning the Discount object arrays. Each
I have a sort of plug-in model in which various complex user controls are
I have several complex data structures like Map< A, Set< B > > Set<
I have a model and in that model I'm generating a more complex field

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.