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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:11:20+00:00 2026-05-25T17:11:20+00:00

How to serialize a rather complex structure into a byte[] array, using BinaryWriter? Update:

  • 0

How to serialize a rather complex structure into a byte[] array, using BinaryWriter?

Update:

  • For this to work, every structure (and sub-structure?) must be decorated with the [Serializable] attribute.

  • I do not need to implement the ISerializable interface, as this is designed to give an object control over its own serialization.

  • 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-25T17:11:20+00:00Added an answer on May 25, 2026 at 5:11 pm

    From comments, the OP’s scenario requires strong compatibility with future versions of the application / .NET, in which case I always advise againt BinaryFormatter – it has many “features” that simply don’t work well between versions (and certainly not between platforms).

    I recommend looking at contract-based serializers; I’m biased, but I lean towards protobuf-net (which maps to Google’s protobuf specification). The easiest way to do this is to attribute the types in such a way that the library can make light work of them (although it can also be done without attributes), for example:

     [ProtoContract]
     public class Customer {
         [ProtoMember(1)]
         public List<Order> Orders {get {....}}
    
         [ProtoMember(2)]
         public string Name {get;set;}
    
         ... etc
     }
    

    (the attribute appoach is very familiar if you’ve done any XmlSerializer or DataContractSerializer work – and indeed protobuf-net can consume the attributes from those if you don’t want to add protobuf-net specific attributes)

    then something like:

    Customer cust = ...
    byte[] data;
    using(var ms = new MemoryStream()) {
        Serializer.Serialize(ms, cust);
        data = ms.ToArray();
    }
    

    The data produced this way is platform independent, and could be loaded on any matching contract (it doesn’t even need to be Customer – it could any type with matching layout via the attributes). Indeed, in most cases it’ll load easily into any other protobuf implementation – Java, C++, etc.

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

Sidebar

Related Questions

This code reloads the entire page rather than simply replacing the #form element every
I'm am trying to serialize a class into both XML & JSON. This is
I am able to serialize an object into a file and then restore it
Is it possible to serialize and deserialize a class in C++? I've been using
Trying to serialize an XmlDocument to file. The XmlDocument is rather large; however, in
I apologize since this is rather a n00bish question, but I can't figure this
I have been happy serializing with javascript objects into JSON using JSON.stringify And sending
I want to XML-Serialize a complex type (class), that has a property of type
I am using DataContractJsonSerializer to serialize an object to json, and then returning to
Running my (rather complex) JavaScript/jQuery application in Google's Chrome browser, it would appear that

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.