1

Below is the class definitions that work and dont' work in a WCF environment running protobuf-net version 2.0.0.480.

Know that the processing code populates the response's list with the real type in hand, in this case SomeClassRow.

And the more bizare thing is that with the bad version of the SomeResponse, the WCF sometimes worked and sometimes didn't.

This is why I use the IDataRow interface. This lets my response's list to hold any types of rows.

So the question is, why is protobuf failing to deserialize when the list is defined with strong type vs. the interface (IDataRow) ?

Thanks,
Ninos

[ProtoContract]
[ProtoInclude(101, typeof(BaseClassInfo))]
public interface IDataRow
{
}

[ProtoContract]
[ProtoInclude(101, typeof(SomeClassRow))]
public class BaseClassInfo : IDataRow
{
   [ProtoMember(1)]
   public int SomeId { get; set; }
   ...
}

// This version of the class won't work because it defines the collection with the
// strongly type name i.e. List<Some
[ProtoContract]
public class SomeResponse
{
   [ProtoMember(1)]
   public List<SomeClassRow> Rows { get; set; }

   ...
}

// SomeClassRow is in turn an IDataRow.
[ProtoContract]
public class SomeClassRow : BaseClassInfo
{
   [ProtoMember(1)]
   public string Name { get; set; }

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

   ...  
}

// But, if the response is defined as follows then the WCF deserializes correcty and ALWAYS.
[ProtoContract]
public class SomeResponse
{
   [ProtoMember(1)]
   public List<IDataRow> Rows { get; set; }

   ...
}
Ninos
  • 224
  • 4
  • 18
  • Can you be specific about "won't work", "sometimes didn't", etc? I think I know the scenario, but it would be good to be 100% clear – Marc Gravell Jul 31 '12 at 08:39
  • It simply didn't deserialize correctly, and what I mean by not working all the time is that I get different exceptions. Sometimes I got the generic "The underlying connection was closed: The connection was closed unexpectedly" and sometimes casting exception of not able to cast such to such, and sometimes "The type cannot be changed once a serializer has been generated". Hope this helps. Ninos – Ninos Jul 31 '12 at 19:11
  • I simply haven't had chance to look at it yet. – Marc Gravell Aug 02 '12 at 17:29
  • haven't forgotten - just a backlog of stuff. Made it into the middle column: https://trello.com/board/protobuf-net-road-map/500900581f3aedaf06ded6ca – Marc Gravell Aug 09 '12 at 06:10

0 Answers0