Why can't I serialize an object using a DataContractSerializer?

I am trying to serialize a type using a DataContractSerializer and get an exception below. This is not for the SOA service, but I would still like to use the DataContractSerializer, if possible. I am using .Net 3.5 SP1.

Type 'System.DelegateSerializationHolder + DelegateEntry' with the data contract name 'DelegateSerializationHolder.DelegateEntry: http://schemas.datacontract.org/2004/07/System ' is not expected. Add any types, not statically known, to the list of known types - for example, using the KnownTypeAttribute attribute or adding them to the list of known types passed to the DataContractSerializer.

+3
source share
2 answers

Can you post a definition of your class?

It looks like you are trying to serialize a class with a delegate field of a type that I am sure will cause the serializer to suffocate.

Have you decorated your class with DataContract / DataMember attributes? 3.5 SP1 uses a serializer by default, which defaults to serializing the entire public class if it is not marked with these attributes. Perhaps you should explicitly mark each property that should be serialized using the DataMember attribute, and leave those that should not.

Other than that, we will need to find out your class definition for more help.

+4
source

Source: https://habr.com/ru/post/1707627/


All Articles