Why string interning on serialization in protobuf-net does not work in this example?
      [ProtoContract]
      public class A
      {
        [ProtoMember(1, AsReference = true)]
        public string Id { get; set; }
    
        public override bool Equals(object obj) { return Id == ((A)obj).Id; }
        public override int GetHashCode() { return Id.GetHashCode(); }
        public override string ToString() { return Id; }
      }
      [ProtoContract]
      public class B
      {
        [ProtoMember(1)]
        public string Id { get; set; }
    
        public override bool Equals(object obj) { return Id == ((B)obj).Id; }
        public override int GetHashCode() { return Id.GetHashCode(); }
        public override string ToString() { return Id; }
      }
    
      class Program
      {
        static void Main()
        {
          var m = RuntimeTypeModel.Default;
          m.Add(typeof(object), false).AddSubType(1, typeof(A)).AddSubType(2, typeof(B));
    
          var list = new List<object> { new A { Id = "Abracadabra" }, new B { Id = "Focuspocus" }, new A { Id = "Abracadabra" }, };
          using (var ms = new MemoryStream())
          {
            m.Serialize(ms, list);
            ms.Position = 0;
            var list2 = (List<object>)m.Deserialize(ms, null, typeof(List<object>));
            Debug.Assert(list.SequenceEqual(list2));
            File.WriteAllBytes(@"output.dump", ms.ToArray());
          }
        }
      }

The produced output.dump file contains two instances of the Abracadabra string, while there should be only one ([http://stackoverflow.com/questions/6463460/how-do-i-enable-string-interning-in-protobuf-net][1]).

I am using v2 rev 421.

Thanks.


  [1]: http://stackoverflow.com/questions/6463460/how-do-i-enable-string-interning-in-protobuf-net
Why string interning on serialization in protobuf-net does not work in this example?
===

      [ProtoContract]
      public class A
      {
        [ProtoMember(1, AsReference = true)]
        public string Id { get; set; }
    
        public override bool Equals(object obj) { return Id == ((A)obj).Id; }
        public override int GetHashCode() { return Id.GetHashCode(); }
        public override string ToString() { return Id; }
      }
      [ProtoContract]
      public class B
      {
        [ProtoMember(1)]
        public string Id { get; set; }
    
        public override bool Equals(object obj) { return Id == ((B)obj).Id; }
        public override int GetHashCode() { return Id.GetHashCode(); }
        public override string ToString() { return Id; }
      }
    
      class Program
      {
        static void Main()
        {
          var m = RuntimeTypeModel.Default;
          m.Add(typeof(object), false).AddSubType(1, typeof(A)).AddSubType(2, typeof(B));
    
          var list = new List<object> { new A { Id = "Abracadabra" }, new B { Id = "Focuspocus" }, new A { Id = "Abracadabra" }, };
          using (var ms = new MemoryStream())
          {
            m.Serialize(ms, list);
            ms.Position = 0;
            var list2 = (List<object>)m.Deserialize(ms, null, typeof(List<object>));
            Debug.Assert(list.SequenceEqual(list2));
            File.WriteAllBytes(@"output.dump", ms.ToArray());
          }
        }
      }

The produced output.dump file contains two instances of the Abracadabra string, while there should be only one ([http://stackoverflow.com/questions/6463460/how-do-i-enable-string-interning-in-protobuf-net][1]).

I am using v2 rev 421.

Thanks.


  [1]: http://stackoverflow.com/questions/6463460/how-do-i-enable-string-interning-in-protobuf-net