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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:02:02+00:00 2026-05-14T18:02:02+00:00

I am trying to serialize a ItemTransaction and protobuf-net (r282) is having a problem.

  • 0

I am trying to serialize a ItemTransaction and protobuf-net (r282) is having a problem.

ItemTransaction : IEnumerable<KeyValuePair<Type, IItemCollection>></code>

and ItemCollection is like this:

FooCollection : ItemCollection<Foo>
ItemCollection<T> : BindingList<T>, IItemCollection
IItemCollection : IList<Item>

where T is a derived type of Item. ItemCollection also has a property of type IItemCollection.

I am serializing like this:

IItemCollection itemCol = someService.Blah(...);
...
SerializeWithLengthPrefix<IItemCollection>(stream, itemCol, PrefixStyle.Base128);

My eventual goal is to serialize ItemTransaction, but am snagged with IItemCollection.

Item and it’s derived types can be [de]serialized with no issues, see [1], but deserializing an IItemCollection fails (serializing works). ItemCollection has a ItemExpression property and when deserializing protobuf can’t create an abstract class. This makes sense to me, but I’m not sure how to get through it.

ItemExpression<T> : ItemExpression, IItemExpression
ItemExpression : Expression

ItemExpression is abstract as is Expression

How do I get this to work properly?

Also, I am concerned that ItemTransaction will fail since the IItemCollections are going to be differing and unknown at compile time (an ItemTransaction will have FooCollection, BarCollection, FlimCollection, FlamCollection, etc).

What am I missing (Marc) ?

[1] protobuf-net [de]serializing across assembly boundaries

  • 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-14T18:02:03+00:00Added an answer on May 14, 2026 at 6:02 pm

    I’m not entirely clear on the entire scenario; however Merge can be used to pass a concrete item in (in the case where you want to create an empty concrete instance yourself and let protobuf-net fill in the properties).

    If the ItemExpression is decorated with [ProtoInclude(...)] for the expected ItemExpression<T> it should allow deserialization – abstract types are supported just as long as it never finds it needs to create one! See also my answer here which shows this in use.

    If you can supply an example that I can use to reproduce the issue I should be able to provide more information.


    Based on some off-forum examples, I think I’ve concluded that this is supported, but:

    • if you just use Deserialize..., the outmost IList<T> derivative will be created by default as List<T>; you can get around this by using Merge instead, passing in a concrete list instance of your choosing to be filled
    • all of Item, Foo, Bar should be marked as contract-types, with appropriate inheritance markers between Item and Foo, and Item and Bar
    • in “v2” (soon) there is more control to manage concrete list types (and item types for untyped lists)
    • there does seem to be a glitch related to list deserialization where the stated item type is not the root type. This looks to have been fixed automatically in “v2”, but I need to chase it through (this unfortunately touches on the wrapper “WithLengthPrefix” / list outermost methods, which I’m still working on)
    • in “v2” you can do the whole thing without needing the attributes if you like (although it still needs to be told how at some point)

    But yes; it should work. I’ve e-mailed you a sample, and intend to tidy up the aforementioned outermost methods.

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

Sidebar

Related Questions

I'm trying to serialize a model using the great Protobuf-NET. I cannot use the
I am trying to serialize/deserialize a List as defined below with protobuf-net v2, and
I'm trying to serialize a Type object in the following way: Type myType =
I'm trying to serialize a type using the DataContractSerializer and am getting the exception
I'm trying to serialize some objects obtained from a 3rd Party .NET Lib to
I have some XML that I am trying serialize like so: string Value =
I am trying to serialize a C# object to JSON using JSON.net library. The
I am trying to serialize a .NET TimeSpan object to XML and it is
I'm trying to serialize a very large IEnumerable<MyObject> using an XmlSerializer without keeping all
I had an odd problem today when I was trying to serialize an object.

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.