Skip to content

XML exception reading message body in .NET 4.5 #16

@NorthNick

Description

@NorthNick

One of our servers was recently upgraded to .NET 4.5 and my .NET 4.0 WcfRestContrib app broke when processing a POST request with a simple text body. The error coming out is:

Error.Message=System.Xml.XmlException%3a+%27Text%27+is+an+invalid+XmlNodeType.
%0d%0a+++at+System.Xml.XmlReader.ReadEndElement()
%0d%0a+++at+WcfRestContrib.ServiceModel.Dispatcher.WebDispatchFormatter.Deserialize(Message+message%2c+WebFormatterFactory+formatterFactory%2c+Object%5b%5d%26+parameters%2c+RequestMessagePartDescription%5b%5d+requestParameters%2c+String+contentType)+in+d%3a%5cTeamCity%5cBuildAgent%5cwork%5cdac2ac50c21c000f%5csrc%5cWcfRestContrib%5cServiceModel%5cDispatcher%5cWebDispatchFormatter.cs%3aline+149
%0d%0a+++at+WcfRestContrib.ServiceModel.Dispatcher.WebDispatchFormatter.DeserializeRequest(Message+message%2c+Object%5b%5d+parameters)+in+d%3a%5cTeamCity%5cBuildAgent%5cwork%5cdac2ac50c21c000f%5csrc%5cWcfRestContrib%5cServiceModel%5cDispatcher%5cWebDispatchFormatter.cs%3aline+73%
0d%0a+++at+System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc%26+rpc)
%0d%0a+++at+System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc%26+rpc)
%0d%0a+++at+System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc%26+rpc)
%0d%0a+++at+System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc%26+rpc)
%0d%0a+++at+System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean+isOperationContextSet)&Error.Status=500

The error is in BInaryBodyReader.cs, at line 15 and the date it's trying to deserialise is a byte stream corresponding to the request body which, for what it's worth, is:

source=TweetDeck&screen%5Fname=d%5Froberts&text=Testing%20Zeitgeist

At this point I'm a bit stuck on how to proceed as I've been unable to find this sort of thing mentioned in any of the .NET 4.5 breaking changes. Any ideas or solutions would be very welcome. Many thanks,

Nick North

PS I am using the WcfRestContrib 1.7.10.0 NuGet package.

PPS I have just realised something else that may be important. I have my own reader for application/x-www-form-encoded data (which this request has as its content type), which is declared with the attributes on the service below. It looks as though my reader is not being invoked.

// Set this as the default MIME type because WCFRestContrib tries to match the entire Content-Type, which includes the boundary string for multipart/form-data
// so cannot be matched, as that is random. We happen to know that anything that is not application/x-www-form-urlencoded is multipart/form-data, so the trick
// works. 
[WebDispatchFormatterConfiguration("multipart/form-data")]
[WebDispatchFormatterMimeType(typeof(FormEncodedFormatter), "application/x-www-form-urlencoded")]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions