Why does deserialization fail for my INotifyPropertyChanged object when there is no PropertyChanged node in my SOAP?

1.2k views Asked by At

I am building a notification listener web service consisting of just one method which will receive a predefined object as the only parameter to the method. I have a service reference to the sender's API where this object and its component objects are defined, and in the auto-generated code of the service reference, most or all of the objects implement System.ComponentModel.INotifyPropertyChanged. Consequently, each has a PropertyChanged member which shows up in my WSDL like this:

<xs:complexType name="DocuSignEnvelopeInformation">
    <xs:sequence>
        <xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/System.ComponentModel" name="PropertyChanged" nillable="true" type="q1:PropertyChangedEventHandler"/>
        ...
    </xs:sequence>
</xs:complexType>

I don't know why these objects need to implement INotifyPropertyChanged, and this PropertyChanged element is never sent by the notification service that calls my listener service, and this should be just fine, because PropertyChanged has the attribute nillable="true". But for some reason an error is thrown every time indicating that it must have the PropertyChanged attribute: "The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.datacontract.org/2004/07/MyNamespace:DocuSignEnvelopeInformation. The InnerException message was 'Error in line 5 position 2162. 'EndElement' 'DocuSignEnvelopeInformation' from namespace 'http://schemas.datacontract.org/2004/07/MyNamespace' is not expected. Expecting element 'PropertyChanged'.'. Please see InnerException for more details."

Why is it expecting the element 'PropertyChanged' if it is marked as nillable? From what I'm reading, nillable means that the attribute is optional in the xml. Is this not true?

1

There are 1 answers

0
Mark Bailey On BEST ANSWER

This is not a complete answer to the question, but for me, this problem went away when I applied the XmlSerializerFormat attribute to my web service method as described here. The default DataContractFormat caused several problems for me of which this error was one. It still does not make sense to me that PropertyChanged would be required when nillable is true. But for what it's worth to anyone finding this, XmlSerializerFormat resolved this as well as other problems that were caused by the default DataContractFormat.