different behavior for Full Framework and .NET Core for xml schema compilation

后端 未结 1 1441
再見小時候
再見小時候 2021-01-12 23:02

here is my validation code:

string xsdPath = \"base.xsd\";
XDocument doc = XDocument.Load(xmlPath);
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(\"         


        
1条回答
  •  别那么骄傲
    2021-01-12 23:42

    I've just tried this, and the reason it doesn't load the included schema is that the resolver it uses to load it is null. This should fix it:

    schemas.XmlResolver = new XmlUrlResolver();
    

    I've done a bit of digging and found that this is a known behavioural change between Deskop & Core that is documented here:

    If the schema being added imports another schema through external URI, Core does not allow resolving that URI by default while Desktop does. To allow the resolution on Core, the following needs to be called before adding the schema: AppContext.SetSwitch("Switch.System.Xml.AllowDefaultResolver", true);

    Obviously, in addition to the switch you can explicitly set a resolver so that you're not using the default.

    0 讨论(0)
提交回复
热议问题