I’m quite new to Silverlight. I’m working for a project which mainly depends on Serialization and Deserialization.
Formerly, for WPF I was comfortable with Serializable classes. For silverlight, I found protobuf would be quite useful. But, I’m troubled with this exception. I don’t know what causes this problem. Please help me out.
I’m using Silverlight 3.0.
protobuf-net r282
Please find the code which I’m using.
[ProtoContract]
public class Report
{
public Report()
{
}
[ProtoMember(1)]
public SubReports SubReports { get; set; }
}
[ProtoContract]
public class SubReports
: List<SubReport>
{
public SubReports()
{
}
[ProtoMember(1)]
public SubReport SubReport { get; set; }
}
[ProtoContract]
public class SubReport
{
public SubReport()
{
}
[ProtoMember(1)]
public string Name { get; set; }
}
The Code I’m using to de-serialize is
public static T Deserialize<T>(Byte[] bytes) where T
: Report
{
return ProtoBuf.Serializer.Deserialize<T>(new MemoryStream(bytes));
}
My sample XML looks similar to
Report
...SubReports
...SubReport Name=”Q1 Report”
...SubReport Name=”Q2 Report”
...SubReport Name=”Q3 Report”
...SubReport Name=”Q4 Report”
Thanks in advance.
Vinodh
(note: I couldn’t reproduce the “group tags” issue; see edit history for my first thoughts on this, now removed; if you can help me reproduce this I’d be grateful)
The problem is
SubReports. You have defined this both as a list and as a serialization entity ([ProtoContract]); the latter takes precedence, so it was trying to serialize the single sub-report on the list (which is alwaysnull?).If you change this to:
or if you remove it completely and make
Report.SubReportsaList<SubReport>it should work fine. The following works:Displaying the blob: