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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:43:59+00:00 2026-05-30T00:43:59+00:00

I’m using the V2 of proto-buf. When I serialize a sample project with 2

  • 0

I’m using the V2 of proto-buf. When I serialize a sample project with 2 classes, proto-buf serializes when I don’t include [ProtoMember(x)] in the fields. I just put [ProtoContract] before the classes. I don’t know why this is happening?

When I tried to serialize my real project after putting [ProtoContract] before all the classes and not adding [ProtoMember(x)] for any fields in any classes, I don’t get an error but the serialized file is empty (0 bytes). Does anyone know what is happening? Do we need to put protomember before every field in order to serialize? If so, why did my sample project get serialized without using any protomember in the project?

My real project has about like 20-30 classes with each having a lot of fields? Do I need to put protomember in all the fields in all the classes?

Thanks for your insight.

  • 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-30T00:44:00+00:00Added an answer on May 30, 2026 at 12:44 am

    Serializing an object with no interesting fields to write is not an error as such – pretty unusual, but not strictly an error – so indeed: it doesn’t complain. Zero bytes is a valid serialization length for protobuf, even with fields to serialize (if they all turn out to be null/default-value/conditional-and-disabled/etc). Actually, this came up earlier this week because the new MS WebAPI assumes (incorrectly in this case) that a payload length of zero bytes is impossible, and so doesn’t invoke the deserializer. Sigh.

    But to answer your question!

    If you are absolutely sure you aren’t going to change your DTOs, you can ask protobuf-net to make up the numbers; this is “ImplicitFields”, and can be done either as:

    • all public members (fields or properties) – this is very much like how XmlSerializer works
    • all fields (private or public) – this is very much like how BinaryFormatter works

    The one issue with ImplicitFields is that: the numbers it generates are essentially the contract. ImplicitFields generates the numbers by ordering alphabetically and just using consecutive numbere. If you change your DTO (add/remove/rename a member) it could start thinking of different numbers, which is a breaking change: any old data on disk / in a database / etc may fail to deserialize correctly.

    If you are sure your contract is fixed, you can enable this via (apologies if I get it a tiny bit wrong – not at a PC):

    [ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
    public class Foo { /* blah blah blah */ }
    

    Of course, you can always change this to explicit [ProtoMember(n)] later – just use 1, 2, 3 etc as per the alphabetical member layout, and then make any changes you want to your DTO.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using Paperclip to handle profile photo uploads in my app. They upload
I have thousands of HTML files to process using Groovy/Java and I need to

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.