How to catch exceptions due to an invalid xml schema (xsd)

SyntaxEditor Web Languages Add-on for WPF Forum

Posted 6 years ago by Tim Scott
Version: 13.1.0582
Avatar

Hi,

When the schema resolver is used to load an xml schema that is syntatically invalid no exception is thrown.

At the next parse cycle a System.Xml.Schema.XmlSchemaException is thrown on the AmbientParseRequestDispatcherProvider and my entire application crashes.

The Application_DispatcherUnhandledException does not catch this situation.

Is there any way to catch this exception?

To reproduce.

1. Save the following  xml schema (which has an invalid elemnet) as an xsd file.

<xs:schema id="BadElementExampleXsd"
targetNamespace="BadElementExampleXsd"
elementFormDefault="qualified"
xmlns="BadElementExampleXsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="BadElement" type="MissingElementType" />

<xs:element name="GoodElement" type="GoodElementType" / >
<xs:complexType name="GoodElementType" >
<xs:attribute name="Name" type="xs:string" />
</xs:complexType>

</xs:schema>

 

2. Using the "Actipro WFP Controls Sample Browser", open the Schema file from 1) via the Synax Editor Xml Editor 

3. The "Actipro WFP Controls Sample Browser" will crash.

 

Here is a sample call stack

System.Xml.Schema.XmlSchemaException was unhandled
HResult=-2146231999
Message=Type 'BadElementExampleXsd.MissingElementType' is not declared.
Source=System.Xml
LineNumber=19
LinePosition=4
SourceUri=""
StackTrace:
at System.Xml.Schema.XmlSchemaSet.InternalValidationCallback(Object sender, ValidationEventArgs e)
at System.Xml.Schema.BaseProcessor.SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
at System.Xml.Schema.Compiler.CompileElement(XmlSchemaElement xe)
at System.Xml.Schema.Compiler.Compile()
at System.Xml.Schema.Compiler.Execute(XmlSchemaSet schemaSet, SchemaInfo schemaCompiledInfo)
at System.Xml.Schema.XmlSchemaSet.Compile()
at ActiproSoftware.Text.Languages.Xml.Implementation.XmlSchemaResolver.#jNc()
at ActiproSoftware.Text.Languages.Xml.Implementation.XmlSchemaResolver.get_SchemaSet()
at ActiproSoftware.Text.Languages.Xml.Implementation.XmlValidator.#qNc(ISyntaxLanguage #p0c)
at ActiproSoftware.Text.Languages.Xml.Implementation.XmlValidator.Validate(IParseRequest request, IAstNode ast)
at ActiproSoftware.Text.Languages.Xml.Implementation.XmlParserBase.Validate(IParseRequest request, IParserState state)
at ActiproSoftware.Text.Languages.Xml.Implementation.XmlParserBase.CreateParseData(IParseRequest request, IParserState state)
at ActiproSoftware.Text.Parsing.LLParser.Implementation.LLParserBase.Parse(IParseRequest request)
at ActiproSoftware.Text.Parsing.Implementation.ThreadedParseRequestDispatcher.#0Yc.#nXc(IParseRequest #FMc)
at ActiproSoftware.Text.Parsing.Implementation.ThreadedParseRequestDispatcher.#0Yc.#56c()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

 

Thanks,

Tim

Comments (2)

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tim,

All you have to do is call the XmlSchemaResolver.SchemaSet property to trigger the SchemaSet it has internally to Compile().  If you wrap that property call with an exception handler before you ever use the language, you can catch it beforehand.

Or you could even build up the XmlSchemaSet on your own and call its Compile() method before setting it to XmlSchemaResolver.SchemaSet.  You can watch for exceptions while calling Compile().


Actipro Software Support

Posted 6 years ago by Tim Scott
Avatar

Thank you. The call to XmlSchemaResolver.SchemaSet is just what I was after.

Regards,

Tim

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.