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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:18:36+00:00 2026-05-23T05:18:36+00:00

If I have object A and B both contain some field serialized field F,

  • 0

If I have object A and B both contain some field serialized field F, and both point to the same serializable object C. Does protobuf-net serialize by reference or serialize by value? When the object graph is deserialized, does protobuf-net generate 2 separate objects for A.F and B.F? I’m asking because I want to know if serialization preserves reference equality.

  • 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-23T05:18:36+00:00Added an answer on May 23, 2026 at 5:18 am

    The raw “protobuf” spec, a defined by Google, is a tree serializer (like XmlSerializer). So by default you would get C serialized twice, and two different objects when deserialized.

    However, this is such a common question that in “v2” I provide this as an opt-in behaviour; note you should only use this for protobuf-net to protobuf-net, as other clients will not expect this configuration (although it remains a valid protobuf stream).

    For example (using attributes, bit you can also use a runtime model instead):

    [ProtoContract]
    public class A {
        ...
        [ProtoMember(5, AsReference=true)]
        public C Foo {get;set;}
    }
    
    [ProtoContract]
    public class B {
        ...
        [ProtoMember(7, AsReference=true)]
        public C Bar {get;set;}
    }
    
    [ProtoContract]
    public class C {...}
    

    This will serialize the instance once, generating an id unique in the output. When deserialized, the same object will be used in both places.

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

Sidebar

Related Questions

I have two projects within one solution. Both projects contain some files that are
I think I read somewhere that some modules only have object oriented interfaces (
I have an object that is mapped to a cookie as a serialized base-64
I have an object graph serialized to xaml. A rough sample of what it
I have two classes, call them A and B. They both contain a Loader
I have two List's that contain a object of Tag like List i need
I have two objects both of the same type, for instance: typedef struct s_Object
I have 2 objects, both of which I want to convert to dictionarys. I
I have two UIImageView objects inside my view (both 320x480 one above the other).
I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit

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.