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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:42:10+00:00 2026-05-30T15:42:10+00:00

This question is related to this one: https://stackoverflow.com/questions/7906356/how-to-solve-a-a-reference-tracked-object-changed-reference-during-deserializat Since the above post has been

  • 0

This question is related to this one: https://stackoverflow.com/questions/7906356/how-to-solve-a-a-reference-tracked-object-changed-reference-during-deserializat

Since the above post has been closed, I created a new one that includes the test code to reproduce the problem and the exception stack trace.

What is going here, why the error? Also I am not clear on the tag for the ProtoInclude. If the tag is equal to a ProtoMember then I get an exception about a duplicate field number. So, I usually set it to max(ProtoMember tag) + 1. Is this what the tool expects?

I run this example with the latest code from svn (downloaded today).

Thanks

[ProtoContract]
[ProtoInclude(6, typeof(B))]
public class A
{
  [ProtoMember(1)]
  public int Property1 { get; set; }

  [ProtoMember(2)]
  public int? Property2 { get; set; }

  [ProtoMember(3)]
  public int Property3 { get; set; }

  [ProtoMember(4, DynamicType = true)]
  public object Property4 { get; set; }

  [ProtoMember(5, DynamicType = true)]
  public object Property5 { get; set; }

  public override bool Equals(object obj)
  {
    A a = obj as A;
    if (a == null)
      return false;

    return a.Property1 == this.Property1
           && a.Property2 == this.Property2
           && a.Property3 == this.Property3
           && Object.Equals(a.Property4, this.Property4)
           && Object.Equals(a.Property5, this.Property5);
  }
}

public class B: A
{
  [ProtoMember(1)]
  public string Property6 { get; set; }

  public override bool Equals(object obj)
  {
    B b = obj as B;
    if (b == null)
      return false;

    return b.Property6 == this.Property6 && base.Equals(obj);
  }
}

[Test]
public void TestProtoBuf2()
{
  IList<A> list = new List<A>
                    {
                      new A {Property1 = 1, Property2 = 1, Property3 = 200, Property4 = "Test1", Property5 = DateTime.Now},
                      new B {Property1 = 2, Property2 = 2, Property3 = 400, Property4 = "Test2", Property5 = DateTime.Now, Property6 = "yyyy"},
                      new A {Property1 = 3, Property2 = 3, Property3 = 600, Property4 = "Test3", Property5 = new Decimal(200)},
                    };
  using (var file = new FileStream("list.bin", FileMode.Create))
  {
    Serializer.Serialize(file, list);
  }

  IList<A> list2;
  using (var file = File.OpenRead("list.bin"))
  {
    list2 = Serializer.Deserialize<IList<A>>(file);
  }

  Assert.AreEqual(list.Count, list2.Count);

  for (int i = 0; i < list.Count; i++)
  {
    Assert.AreEqual(list[i], list2[i]);
  }
}

Stack trace:

at ProtoBuf.BclHelpers.ReadNetObject(Object value, ProtoReader source, Int32 key, Type type, NetObjectOptions options) in BclHelpers.cs: line 444
at ProtoBuf.Serializers.NetObjectSerializer.Read(Object value, ProtoReader source) in C:\Development\dotnet\protobuf-net\protobuf-net\Serializers\NetObjectSerializer.cs: line 37
at ProtoBuf.Serializers.TagDecorator.Read(Object value, ProtoReader source) in C:\Development\dotnet\protobuf-net\protobuf-net\Serializers\TagDecorator.cs: line 61
at ProtoBuf.Serializers.PropertyDecorator.Read(Object value, ProtoReader source) in C:\Development\dotnet\protobuf-net\protobuf-net\Serializers\PropertyDecorator.cs: line 53
at ProtoBuf.Serializers.TypeSerializer.Read(Object value, ProtoReader source) in TypeSerializer.cs: line 200
at ProtoBuf.Meta.RuntimeTypeModel.Deserialize(Int32 key, Object value, ProtoReader source) in C:\Development\dotnet\protobuf-net\protobuf-net\Meta\RuntimeTypeModel.cs: line 418
at ProtoBuf.Meta.TypeModel.TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, Int32 tag, Type type, ref Object value, Boolean skipOtherFields, Boolean asListItem, Boolean autoCreate, Boolean insideList) in C:\Development\dotnet\protobuf-net\protobuf-net\Meta\TypeModel.cs: line 895
at ProtoBuf.Meta.TypeModel.TryDeserializeList(ProtoReader reader, DataFormat format, Int32 tag, Type listType, Type itemType, ref Object value) in C:\Development\dotnet\protobuf-net\protobuf-net\Meta\TypeModel.cs: line 712
at ProtoBuf.Meta.TypeModel.TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, Int32 tag, Type type, ref Object value, Boolean skipOtherFields, Boolean asListItem, Boolean autoCreate, Boolean insideList) in C:\Development\dotnet\protobuf-net\protobuf-net\Meta\TypeModel.cs: line 851
at ProtoBuf.Meta.TypeModel.DeserializeCore(ProtoReader reader, Type type, Object value, Boolean noAutoCreate) in C:\Development\dotnet\protobuf-net\protobuf-net\Meta\TypeModel.cs: line 594
at ProtoBuf.Meta.TypeModel.Deserialize(Stream source, Object value, Type type, SerializationContext context) in C:\Development\dotnet\protobuf-net\protobuf-net\Meta\TypeModel.cs: line 518
at ProtoBuf.Meta.TypeModel.Deserialize(Stream source, Object value, Type type) in C:\Development\dotnet\protobuf-net\protobuf-net\Meta\TypeModel.cs: line 500
at ProtoBuf.Serializer.Deserialize(Stream source) in C:\Development\dotnet\protobuf-net\protobuf-net\Serializer.cs: line 69
  • 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-30T15:42:11+00:00Added an answer on May 30, 2026 at 3:42 pm

    Re the field number; they need to be unique within a single type; it is not required that it is “max + 1” – they don’t have to be contiguous – however, small numbers are preferable (as long as they are positive), as “varint” encoding can pack low field numbers (for headers) more efficiently.

    Re the reference-tracking issue; this is a bug and is fixed in the current trunk – thanks; an edge case, but fixed.

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

Sidebar

Related Questions

This question is related with one of my earlier questions.. Previous Post In there
NOTE: I have a related question here (http://stackoverflow.com/questions/6915055/are-jsf-views-shared-between-users) but that deals with a few
The code related to this question is here: https://github.com/jchester/lua-polarssl/tree/master/src Currently I'm trying to wrap
This question is related to this one , though I think I was a
This question is related to this one . I have a page table with
[This question is related to but not the same as this one .] My
[This question is related to but not the same as this one .] If
Another question related to this one . I have a List<SortableObjects> that is the
I have a question related to this one . I don't want to do
I have a question related to this one : I'm trying to attach an

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.