2

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?

4

1 回答 1

3

听起来您正在使用BinaryFormatter- 但是,WCF 类型用于使用DataContractSerializer或相关的序列化程序(NetDataContractSerializer、protobuf-net 等)进行序列化。尝试DataContractSerializer改用 - 你的问题应该消失。

于 2012-04-29T19:14:33.543 回答