I'm running into an Exception error when trying to validate an XML file against a schema in MVC/ASP.Net Core.
The error I'm getting is this:
System.Xml.Schema.XmlSchemaValidationException: 'Type 'http://ns.editeur.org/onix/3.0/reference:SourceTypeCode' is not declared, or is not a simple type.'
My code is this:
XmlSchemaSet onixschema = new XmlSchemaSet();
XDocument xmlDocument = XDocument.Load(@"path.to.xml.file");
onixschema.Add("http://ns.editeur.org/onix/3.0/reference", @"path.to.ONIX_BookProduct_3.0_reference.xsd");
xmlDocument.Validate(onixschema, (o, e) =>
{
validationResult.ErrorMessages.Add(e.Message);
});
I don't really know where to start with the exception. The message isn't wildly enlightening!
And the really baffling thing is that if I run this exact code in WebForms/.Net (same files, etc), it validates correctly.
I don't get the error.
If anybody was able to shed some light on this, I'd be very grateful.
//Edit
Pretty sure it has something to do with ASP.Net Core. If I create a brand new MVC/.Net web app, and stick the code in the Home Controller, it works as it should. No validation exception.
If I create a brand new MVC/ASP.NET Core App, and stick the code in the Home Controller, it fails, with the validation exception.
Could it be to do with the way ASP.NET Core handles the static XSD file?