I am trying to convert an XmlSchema object to a string.
I create a simple XmlSchema, compile it, and then convert it as follows:
public string ConvertXmlSchemaToString(XmlSchema xmlSchema) { String schemaAsString = String.Empty; // compile the schema XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(xmlSchema); schemaSet.ValidationEventHandler += new ValidationEventHandler(schemaSet_ValidationEventHandler); schemaSet.Compile(); // allocate memory for string output MemoryStream memStream = new MemoryStream(1024); xmlSchema.Write(memStream); memStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(memStream); schemaAsString = reader.ReadToEnd(); return schemaAsString; }
While working as a console application, everything works fine, but when I start from Nunit, I get an exception in "xmlSchema.Write (memStream)"; line.
Exception: Error creating XML document.
Internal exception
: Common Language Runtime detects an invalid program.
Yossin
source share