title: XmlDocument.Load() throws XmlSchemaValidationException
body: <p>I'm trying to validate an XML document against a schema (which is embedded in my program as a resource). I got everything to work, so I tried to test for errors by adding a second sibling node in the XML at a location where the schema specifies <code>maxOccurs="1"</code>. The problem is that my <code>ValidationEventHandler</code> is never getting called, also <code>XmlDocument.Load()</code> is throwing an <code>XmlSchemaValidationException</code> exception when I'd expected <code>XmlDocument.Validate()</code> to do that. </p>
  
  <p>This is the code I have:</p>
  
  <pre><code>private void ValidateUserData( string xmlPath )
  {
    var resInfo = Application.GetResourceStream( new Uri( @"MySchema.xsd", 
                     UriKind.Relative ) );
    var schema = XmlSchema.Read( resInfo.Stream, SchemaValidationCallBack );
  
    XmlSchemaSet schemaSet = new XmlSchemaSet();
    schemaSet.Add( schema );
    schemaSet.ValidationEventHandler += SchemaValidationCallBack;
  
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.Schemas = schemaSet;
    settings.ValidationType = ValidationType.Schema;
  
    XmlDocument doc = new XmlDocument();
    using( XmlReader reader = XmlReader.Create( xmlPath, settings ) ) {
      doc.Load( reader ); // &lt;-- This line throws an exception if XML is ill-formed
      reader.Close();
    }
    doc.Validate( SchemaValidationCallBack );// &lt;-- This is never reached
  }
  
  private void SchemaValidationCallBack( object sender, ValidationEventArgs e )
  {
    Console.WriteLine( "SchemaValidationCallBack: " + e.Message );
  }
  </code></pre>
  
  <p>How do I get the callback to be called so I can handle validation errors?</p>
  
  <p>Thanks for your help!</p>