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

  • Home
  • SEARCH
  • 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 236155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:19:21+00:00 2026-05-11T20:19:21+00:00

I have a List<object> with different types of objects in it like integers, strings,

  • 0

I have a List<object> with different types of objects in it like integers, strings, and custom types. All custom types are protobuf-adjusted.
What I wanna do now is to serialize / deserialize this list with protobuf.net. Up until now I suspect that I have to declare each and every type explicitly, which is unfortunately not possible with these mixed-list constructs. Because the binary formater has no problems to do these things I hope that I missed something and that you can help me out.
So my question is how to deal with objects in protobuf.net.

  • 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-11T20:19:21+00:00Added an answer on May 11, 2026 at 8:19 pm

    (disclosure: I’m the author of protobuf-net)

    BinaryFormatter is a metadata-based serializer; i.e. it sends .NET type information about every object serialized. protobuf-net is a contract-based serializer (the binary equivalent of XmlSerializer / DataContractSerializer, which will also reject this).

    There is no current mechanism for transporting arbitrary objects, since the other end will have no way of knowing what you are sending; however, if you have a known set of different object types you want to send, there may be options. There is also work in the pipeline to allow runtime-extensible schemas (rather than just attributes, which are fixed at build) – but this is far from complete.


    This isn’t ideal, but it works… it should be easier when I’ve completed the work to support runtime schemas:

    using System;
    using System.Collections.Generic;
    using ProtoBuf;
    [ProtoContract]
    [ProtoInclude(10, typeof(DataItem<int>))]
    [ProtoInclude(11, typeof(DataItem<string>))]
    [ProtoInclude(12, typeof(DataItem<DateTime>))]
    [ProtoInclude(13, typeof(DataItem<Foo>))]
    abstract class DataItem {
        public static DataItem<T> Create<T>(T value) {
            return new DataItem<T>(value);
        }
        public object Value {
            get { return ValueImpl; }
            set { ValueImpl = value; }
        }
        protected abstract object ValueImpl {get;set;}
        protected DataItem() { }
    }
    [ProtoContract]
    sealed class DataItem<T> : DataItem {
        public DataItem() { }
        public DataItem(T value) { Value = value; }
        [ProtoMember(1)]
        public new T Value { get; set; }
        protected override object ValueImpl {
            get { return Value; }
            set { Value = (T)value; }
        }
    }
    [ProtoContract]
    public class Foo {
        [ProtoMember(1)]
        public string Bar { get; set; }
        public override string ToString() {
            return "Foo with Bar=" + Bar;
        }
    }
    static class Program {
        static void Main() {
            var items = new List<DataItem>();
            items.Add(DataItem.Create(12345));
            items.Add(DataItem.Create(DateTime.Today));
            items.Add(DataItem.Create("abcde"));
            items.Add(DataItem.Create(new Foo { Bar = "Marc" }));
            items.Add(DataItem.Create(67890));
    
            // serialize and deserialize
            var clone = Serializer.DeepClone(items);
            foreach (DataItem item in clone) {
                Console.WriteLine(item.Value);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 206k
  • Answers 206k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assuming you have control over both the server and client,… May 12, 2026 at 9:12 pm
  • Editorial Team
    Editorial Team added an answer Strange way to split strings you have there: def splitter(… May 12, 2026 at 9:12 pm
  • Editorial Team
    Editorial Team added an answer You can use XSD.EXE, and the command will be something… May 12, 2026 at 9:12 pm

Related Questions

I have a stateless bean something like: @Stateless public class MyStatelessBean implements MyStatelessLocal, MyStatelessRemote
I have these container objects (let's call them Container) in a list. Each of
I'm having trouble converting the following SQL-statement to LINQ-to-entities: SELECT l.* FROM locations l
This one is fairly complex, hopefully I can make this clear enough for somebody

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.