When using Silverlight, you may want to deserialize some data. Because XmlSerializer is not supported, you could peek DataContractSerializer (system.runtime.serialization.dll). In some specific scenario I had an observable list, which contains elements of some custom type named ServiceInfo.
Unfortunately, if you use the common serialization code shown below to serialize the (observable) list, following exception will be thrown:
Type 'ServiceInfo' with data contract name 'ServiceInfo:http://schemas.datacontract.org/2004/07/...' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
To fix this problem the underlying type used as list element has to be added as known type. Following code shows how to do that:
Posted
Aug 04 2008, 02:24 PM
by
Damir Dobric