Tuesday, September 28, 2010

WCF, CSLA, Binary Serialisation and XmlException

We've been having some issues with using CSLA and the WCF DataPortal where we are seeing a stack of System.Xml.XmlExceptions appearing in the output window with no immediately discernible cause. Turning on "Break on unhandled exceptions" yielded the following exception message:

The '<' character, hexadecimal value 0x3C, cannot be included in a name.

We're using binary serialisation, and it turns out that the backing fields created for automatic properties are to blame - they wrap the type name in angle brackets and append a unique suffix.

The only apparent solution to this is to not use automatic properties - binary serialisation works with fields, not properties, and we have no control of the naming convention used for backing fields of automatic properties. Using the [field:NonSerialized] attribute also did not work, unfortunately.

I'm not 100% sure why this results in an XmlException, since we're using binary serialisation, but I'm assuming WCF will wrap all responses in an XML packet regardless. I'm also not sure if this is something that is specific to CSLA or just WCF in general, but if you're seeing this exception in your output window, automatic properties are to blame.

Labels: , ,


Post a Comment

Note: Only a member of this blog may post a comment.

<< Home