Thursday 4 June 2009

Fix - "There is an error in XML document (1, 2)" when deserializing an InfoPath 2007 in a SharePoint Workflow

If you are getting the following errors when attempting to deserialize an InfoPath Form for use in a workflow:
  1. "There is an error in XML document (1, 2)" And the the Inner Exception is
  2. <myFields xmlns=''> was not expected.

Then I suggest that you first check the following:

  1. The root element name of your InfoPath form (by default called "myfields") MUST match the class name of your xsd.exe-generated mapping file.

Otherwise the XmlSerializer will be looking for a root "myfields" (the default name) element in your C# class and it won't be able to map it to the equivalent element in your InfoPath Xml.

In other words, the xsd.exe generated wrapper class name must match the root element name of your InfoPath form.

For reference, I had this issue and it was simply because I renamed the class name of my xsd.exe-generated file (but I didn't rename my root Infopath element) and so the Serializer couldn't map the new class name to the old root element name in my InfoPath form.


Ahmed Salem said...

Thanks so much, this was very helpful!

Nagarajan said...

Thanks, you saved my time

Nagarajan Palaniappan