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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:39:02+00:00 2026-05-23T03:39:02+00:00

[DataContract] public class I<TId> { [DataMember(Order = 1)] public TId Id { get; set;

  • 0
  [DataContract]
  public class I<TId>
  {
    [DataMember(Order = 1)]
    public TId Id { get; set; }
  }

  [DataContract]
  public class J : I<int>
  {
    [DataMember(Order = 1)]
    public string Description { get; set; }
  }

  class Program
  {
    static void Main()
    {
      var o = new J { Id = 5, Description = "xa-xa", };
      using (var ms = new MemoryStream())
      {
        Serializer.Serialize(ms, o);
        ms.Position = 0;
        var o2 = Serializer.Deserialize<J>(ms);
        Debug.Assert(o.Id == o2.Id);
      }
    }
  }

Why does the assertion fail and how to fix it?

Thanks.

  • 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-23T03:39:02+00:00Added an answer on May 23, 2026 at 3:39 am

    It fails because protobuf-net can’t process inheritance unless you give it more of a clue either via attributes or a runtime type-model – essentially it needs to get a field number from somewhere (i.e. you). I am content to concede that maybe a trace warning might be useful in this case, since it is reasonably clear that there is probably more to this inheritance scenario than just J.

    The following addition (at runtime) fixes it:

    RuntimeTypeModel.Default.Add(typeof(I<int>), true).AddSubType(2, typeof(J));
    

    (the only significance of 2 there is that it doesn’t conflict with any other fields defined for I<int>).

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

Sidebar

Related Questions

Given these types: [DataContract] public class EntityId { [DataMember(Order = 1)] public string IdAsString
Consider this type: [DataContract] public class EntityId { [DataMember(Order = 1)] public string IdAsString
[DataContract] public class SearchResults { [DataMember] public List<SearchDetail> PList { get; set; } [DataMemberAttribute]
The case is: [ServiceContract] public interface IInfo { [DataMember] int Id{get;set;} } [DataContract] [KnownType(typeof(Legal))]
I have the following DTO definition:- [DataContract] public class AddProductDTO { [DataMember] public string
Given this: namespace TheEntities { [DataContract(IsReference=true)] public class Question { [DataMember] public virtual int
I have a class in WCF: [DataContract] public class Usuario { [DataMember] public int
I have two classes as below: [DataContract] public class Address { [DataMember] public string
I have this type: [Serializable, DataContract] public class A { [DataMember(Order = 1)] public
I have a simple data contract: [DataContract] public class MyData { [DataMember] public string

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.