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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:40:32+00:00 2026-05-16T04:40:32+00:00

I am having trouble figuring out how to get protobuf-net to serialize an object

  • 0

I am having trouble figuring out how to get protobuf-net to serialize an object that derives from List< T >. I have tried adding the ProtoInclude attribute but I receive an ProtoBuf.ProtoException : Known-type List`1 for ProtoIncludeAttribute must be a direct subclass of UserTypeCollection. When I remove the ProtoInclude attrib it appears the data is not being serialized at all. I can not seem to find any examples of this situation anywhere. I am adding protobuf serialization as an option for our WS api and need to maintain compatibility with DataContractSerializer.

[CollectionDataContract(), ProtoContract(InferTagFromName = true)]
[ProtoInclude(100, typeof(List<UserType>))]
public class UserTypeCollection : List<UserType>
{ ... }

[DataContract(), ProtoContract(InferTagFromName = true)]
public class UserType { ... }
  • 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-16T04:40:33+00:00Added an answer on May 16, 2026 at 4:40 am

    ProtoInclude is used to denote sub types, not base types (after all, the base-type is already known). Also, the IList<T> handling should largely be implicit; note that the “infer…” etc do very little in the case of lists, since lists are just a sequence of the contained items.

    For the following, I’m assuming that you are trying to serialize the list (as the top-most object):

    I’m not on the right machine at the moment, but in the released dlls, I would expect that wrapping the list via an object would make it work:

    [DataContract]
    public class Foo {
        private readonly UserTypeCollection items = new UserTypeCollection();
        [DataMember(Order=1)]
        public UserTypeCollection Items {get{return items;}}
    }
    

    In “v2” I would hope that this scenario works from the outset. I’ll try to test this tomorrow (when I’ll have the right machine).

    One other thought; subclassing List<T> isn’t usually very useful, since none of the methods are virtual. Up to you, of course. And a final note – in “v2” we can describe the model externally if you want to have more control over the serialization but without impacting the types themselves.

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

Sidebar

Related Questions

I'm having trouble figuring out how to access a cookie from a compiled object.
I'm having trouble figuring out how to get the testing framework set up and
(vb.net/c#/etc) I am having trouble figuring out how to do a bit of deserialization
I'm experimenting with Linq and am having trouble figuring out grouping. I've gone through
I'm having a little trouble figuring out exactly how const applies in a specific
I'm having some conceptual trouble on figuring out how to best implement this... I
Im having trouble using a .NET COM in vb6, It compiles ok and I
I having trouble in dividing the HTML frames. I have been using the following
I am having trouble with IE7. I have a header, which is an IMG.
Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the

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.