Any reason why SaxonCS would output certain errors to the console although my code catches and handles the SaxonApiException?
I have a .NET 6 GUI application (using the AvaloniaUI framework) that uses SaxonCS for XSLT/XQuery/XPath processing. For some reasons I haven't understood some errors I get during XML parsing or XSLT or XQuery processing that are caught as a SaxonApiException by my code and displayed in the GUI are as well output to the console (as long as I run the code with dotnet ProgramName.dll from the console) e.g. there I see
Error in urn:from-string: Error reported by XML parser processing urn:from-string at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Impl.Helpers.DotNetPullProvider.next() : Root element is missing.
Error on line 13 column 6 of urn:from-string: XTDE0560 There is no current template rule at template xsl:initial-template on line 12 column 4 of urn:from-string
I am not able to reproduce that in a simple console application just doing the parsing or processing and catching the exception, there I only get my program's output to the console.
RE: Any reason why SaxonCS would output certain errors to the console although my code catches and handles the SaxonApiException? - Added by Michael Kay 7 months ago
Sorry, I can't see any obvious cause. Would need to have a repro and debug it. It's not at all inconceivable that there's a rogue call that prints the stack trace of an exception before rethrowing it, but if there is, I can't find it.
RE: Any reason why SaxonCS would output certain errors to the console although my code catches and handles the SaxonApiException? - Added by Martin Honnen 7 months ago
I think I might be seeing just the effect of what the documentation in https://www.saxonica.com/html/documentation12/dotnetdoc/Saxon/Api/XsltCompiler.html#Compile(TextReader) describes:
Throws a SaxonApiException if errors were detected during static analysis of the stylesheet. Details of the errors will be reported to the ErrorReporter if supplied; otherwise they will be written to the standard error stream. The exception that is returned from this method is merely a summary indicating the status, and is not useful for diagnosing the actual error.
I will try to see whether an ErrorReporter set up ensures that the error(s) do no longer show up on the console
That seems to solve the problem for XSLT processing as there I can set up an ErrorReporter on both the XsltCompiler and the Xslt30Transformer.
However, for XQuery processing and run-time errors/dynamic errors during XQuery evaluation, I wonder why https://www.saxonica.com/html/documentation12/dotnetdoc/Saxon/Api/XQueryEvaluator.html on the .NET/SaxonCS side doesn't have an ErrorReporter while the Java API does have one: https://www.saxonica.com/html/documentation12/javadoc/net/sf/saxon/s9api/XQueryEvaluator.html#setErrorReporter(net.sf.saxon.lib.ErrorReporter)
Please register to reply