XmlSchemaException Class
Collapse the table of content
Expand the table of content

XmlSchemaException Class

Returns detailed information about the schema exception.

Namespace: System.Xml.Schema
Assembly: System.Xml (in system.xml.dll)

public ref class XmlSchemaException : public SystemException
/** @attribute SerializableAttribute() */ 
public class XmlSchemaException extends SystemException
public class XmlSchemaException extends SystemException
Not applicable.

Security noteSecurity Note:

The XmlSchemaException class may contain sensitive information that should not be exposed in untrusted scenarios. For example, the SourceUri property returns the URI path to the schema file that caused the exception. The SourceUri property should not be exposed in untrusted scenarios. Exceptions should be properly handled so that this sensitive information is not exposed in untrusted scenarios.

The following example shows the use of the XmlSchemaException class.

#using <mscorlib.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Schema;

class ValidXsd

    static void Main()
        FileStream^ fs;
        XmlSchema^ schema;

			fs = gcnew FileStream("example.xsd", FileMode::Open);
			schema = XmlSchema::Read(fs, gcnew ValidationEventHandler(ShowCompileError));

            XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
            schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ShowCompileError);

            XmlSchema^ compiledSchema;

            for each (XmlSchema^ schema1 in schemaSet->Schemas())
                compiledSchema = schema1;

            schema = compiledSchema;

            if (schema->IsCompiled)
                // Schema is successfully compiled. 
                // Do something with it here.

        catch (XmlSchemaException^ e)
			Console::WriteLine("LineNumber = {0}", e->LineNumber);
			Console::WriteLine("LinePosition = {0}", e->LinePosition);
			Console::WriteLine("Message = {0}", e->Message);


    static void ShowCompileError(Object^ sender, ValidationEventArgs^ e)
		Console::WriteLine("Validation Error: {0}", e->Message);

int main()
    return 0;

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

© 2016 Microsoft