我正在尝试将 XmlSchema 对象转换为字符串。
我正在构建一个简单的 XmlSchema,对其进行编译,然后将其转换如下:
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;
}
作为控制台应用程序运行时,一切正常,但是从 Nunit 运行时,我在“xmlSchema.Write(memStream);”中出现异常 线。
例外是:生成 XML 文档时出错。
内部异常是:公共语言运行时检测到无效程序。