Invoke operation '...' failed. Error in deserializing body of request message for operation '...'. OperationFormatter encountered an invalid Message body.

Sometimes even long error messages don't tell you much. This one is over 300 characters long and still does not clearly indicate what is wrong:

Invoke operation '...' failed. Error in deserializing body of request message for operation '...'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name '...' and namespace '...'. Found node type 'None' with name '' and namespace ''

Sure, considering the line of code where it was thrown it told me that WCF (RIA Services) failed to return an object in a call. I have hundreds of calls that work fine. Why did this one fail? 

I could not find it. So I decided to work around it and serialize the object myself:

    string result;
    var sb = new StringBuilder();
    using (TextWriter tw = new StringWriter(sb))
    {
       XmlSerializer ser = new XmlSerializer(typeof(...));
       ser.Serialize(tw, theObject);
       result = sb.ToString();
    }
    return result;

When this code ran it revealed the error (in the InnerException): I had a field of type enum, and the value I assigned to it (coming from a database) was not valid - I had forgotten to update the enum definition.

Anyhow, the bottom line is that if you get the long error message mentioned above you might want to serialize the object yourself, so that a more precise error message is revealed.

Print | posted on Monday, December 17, 2012 9:25 PM

Feedback

No comments posted yet.

Your comment:





 
 

Copyright © Marc Schluper

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski