I have a class like so:
[XmlRoot"MyMessageType")]
public class MyMessageType : BaseMessageType
{
[XmlElement("MessageId")]
//Property for MessageId
...
<snip>
//end properties.
}
This class contains a static method to create an XmlDocument instance to pass to a BizTalk server. Like so:
public static XmlDocument GetMyMessageType(string input1, string input2 ...)
GetMyMessageType
creates an instance of MyMessageType, then calls the following code:
XmlSerializer outSer = new XmlSerializer(instance.GetType());
using (MemoryStream mem = new MemoryStream())
using (XmlWriter _xWrite = XmlWriter.Create(mem))
{
outSer.Serialize(_xWrite, instance);
XmlDocument outDoc = new XmlDocument();
outDoc.Load(XmlReader.Create(mem));
return outDoc;
}
When I attempt to run this code, I receive an XmlException
"The Root Element is Missing." When I modify the code to output to a test file, I get a well-formed Xml document. Can anyone tell me why I would be able to output to a file, but not as an XmlDocument?