I’m using a WCF service with an code, which was generated from a mex endpoint.
I would like to be able serialize the classes, which were automatically generated.
My problem is, that those auto-generated classes implement System.ComponentModel.INotifyPropertyChanged interface, and occasionally when serializing them, I’m getting following exception:
Type 'System.ComponentModel.PropertyChangedEventManager' in
Assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
Normally I would deal with this exception by adding [NonSerializable] to the PropertyChanged event, but here the code is auto-generated, and I don’t want to change it.
What is the best way to deal with this problem?
It sounds like you are using
BinaryFormatter– however, WCF types are intended for serialization withDataContractSerializer, or related serializers (NetDataContractSerializer, protobuf-net, etc). Try usingDataContractSerializerinstead – your problem should evaporate.