1

I'm serializing a list of ObservableCollection<MyType> using this line of code and it works fine:

var serializer = new SharpSerializer(true);
serializer.Serialize(myList, myStreamObject);

The problem occurs when I try to deserialize my data.

var serializer = new SharpSerializer(true);
this.items = (ObservableCollection<MyType>)serializer.Deserialize(
    myStreamObject);

When I debug the return type of serializer.Deserialize(myStreamObject) is:

System.Collections.ObjectModel.ObservableCollection`1[MyNameSpace.MyType]

Thereby resulting in typecast error? How do I solve this problem? What am I doing wrong when deserializing?

Thanks

Eliahu Aaron
  • 4,103
  • 5
  • 27
  • 37
Richard
  • 14,427
  • 9
  • 57
  • 85

1 Answers1

2

I don't know if you're using SharpSerializer for Silverlight or for the full .NET As default SharpSerializer serializes data as short type name. It could be the most probable reason of your error. Try to serialize your data as an AssemblyFullQualifiedName:

var settings = new SharpSerializerBinarySettings();
settings.IncludeAssemblyVersionInTypeName = true;
settings.IncludeCultureInTypeName = true;
settings.IncludePublicKeyTokenInTypeName = true;

var serializer = new SharpSerializer(settings);
Curtis
  • 101,612
  • 66
  • 270
  • 352
polo
  • 61
  • 2