What is causing an XmlException (Root element is missing)?

SyntaxEditor .NET Languages Add-on for Windows Forms Forum

Posted 10 years ago by Craig - Varigence, Inc.
Version: 4.0.0281
Avatar
We've recently turned on first chance exceptions in an application that uses the syntax editor, and we've noticed two instances where a XmlException is thrown. We're looking for help in understanding why the exceptions are thrown and what we can do to prevent them.

1. In one scenario, we're initializing a WPF control that hosts the syntax editor. Before any text is set in the editor, I'm setting the OutliningMode property to Automatic, which produces the below callstack (Callstack #1), ending in a thrown exception. Is this simply a matter of not setting OutliningMode when no text is present? Does the SemanticParser service need to be off when setting OutliningMode?

2. There are times when we directly set the editor's Text property, typically when we're switching from one item in our application to another. On our main thread, we produce a call to OnTextChanged. However, the SemanticParser service thread is also running and produces an exception (see Callstack #2).

We seem to be butting heads with the Semantic Parser service - are there times where we need to turn it off? Is there some documentation that clarifies when it's not OK to run it.

Thanks very much,

-Craig


Callstack 1:
System.Xml.dll!System.Xml.XmlTextReaderImpl.Throw(System.Exception e) Line 2181 + 0x7 bytes C#
System.Xml.dll!System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(string res) Line 2190 C#
System.Xml.dll!System.Xml.XmlTextReaderImpl.ParseDocumentContent() Line 3298 + 0xf bytes C#
System.Xml.dll!System.Xml.XmlTextReaderImpl.Read() Line 884 + 0x7 bytes C#
System.Xml.dll!System.Xml.XsdValidatingReader.Read() Line 1066 + 0xb bytes C#
ActiproSoftware.SyntaxEditor.Addons.Web.Net20.dll!ActiproSoftware.SyntaxEditor.Addons.Xml.XmlSchemaResolver.a(string A_0 = "", int A_1 = 0, ActiproSoftware.SyntaxEditor.TextRange A_2 = {StartOffset=-1,EndOffset=-1}) + 0x381 bytes
ActiproSoftware.SyntaxEditor.Addons.Web.Net20.dll!ActiproSoftware.SyntaxEditor.Addons.Xml.XmlSyntaxLanguage.ActiproSoftware.SyntaxEditor.ISemanticParserServiceProcessor.Process(ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest request = {ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest}) + 0x31f bytes
ActiproSoftware.SyntaxEditor.Net20.dll!ActiproSoftware.SyntaxEditor.SemanticParserService.a(ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest A_0 = {ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest}) + 0x138 bytes
ActiproSoftware.SyntaxEditor.Net20.dll!ActiproSoftware.SyntaxEditor.SemanticParserService.b(ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest A_0 = {ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest}) + 0xa1 bytes
ActiproSoftware.SyntaxEditor.Net20.dll!ActiproSoftware.SyntaxEditor.SemanticParserService.Parse(ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest request = {ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest}) + 0x1e bytes
ActiproSoftware.SyntaxEditor.Addons.Web.Net20.dll!ActiproSoftware.SyntaxEditor.Addons.Xml.XmlSyntaxLanguage.PerformSemanticParse(ActiproSoftware.SyntaxEditor.Document document = {ActiproSoftware.SyntaxEditor.Document}, ActiproSoftware.SyntaxEditor.TextRange parseTextRange = {StartOffset=0,EndOffset=0}, ActiproSoftware.SyntaxEditor.SemanticParseFlags flags = ProgrammaticTextReplacement) + 0x91 bytes
ActiproSoftware.SyntaxEditor.Net20.dll!ActiproSoftware.SyntaxEditor.Document.Reparse() + 0x80 bytes
ActiproSoftware.SyntaxEditor.Net20.dll!ActiproSoftware.SyntaxEditor.Document.a(System.EventArgs A_0 = {System.EventArgs}) + 0x46 bytes
ActiproSoftware.SyntaxEditor.Net20.dll!ActiproSoftware.SyntaxEditor.Outlining.Mode.set(ActiproSoftware.SyntaxEditor.OutliningMode value = Automatic) + 0x47 bytes

Callstack 2:
System.Xml.dll!System.Xml.XmlTextReaderImpl.Throw(System.Exception e) Line 2181 + 0x7 bytes C#
System.Xml.dll!System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(string res) Line 2190 C#
System.Xml.dll!System.Xml.XmlTextReaderImpl.ParseDocumentContent() Line 3298 + 0xf bytes C#
System.Xml.dll!System.Xml.XmlTextReaderImpl.Read() Line 884 + 0x7 bytes C#
System.Xml.dll!System.Xml.XsdValidatingReader.Read() Line 1066 + 0xb bytes C#
ActiproSoftware.SyntaxEditor.Addons.Web.Net20.dll!ActiproSoftware.SyntaxEditor.Addons.Xml.XmlSchemaResolver.a(string A_0 = "", int A_1 = 0, ActiproSoftware.SyntaxEditor.TextRange A_2 = {StartOffset=-1,EndOffset=-1}) + 0x381 bytes
ActiproSoftware.SyntaxEditor.Addons.Web.Net20.dll!ActiproSoftware.SyntaxEditor.Addons.Xml.XmlSyntaxLanguage.ActiproSoftware.SyntaxEditor.ISemanticParserServiceProcessor.Process(ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest request = {ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest}) + 0x31f bytes
ActiproSoftware.SyntaxEditor.Net20.dll!ActiproSoftware.SyntaxEditor.SemanticParserService.a(ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest A_0 = {ActiproSoftware.SyntaxEditor.SemanticParserServiceRequest}) + 0x138 bytes
ActiproSoftware.SyntaxEditor.Net20.dll!ActiproSoftware.SyntaxEditor.SemanticParserService.c() + 0x78 bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Line 61 + 0xffffffe3 bytes C#
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 355 + 0xd bytes C#
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Line 88 + 0xffffffe4 bytes C#

Comments (1)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

You'll notice in both cases there is a call to XsdValidatingReader.Read. We use the validating reader to examine the contents of the document and look for errors. While it does work great, unfortunately it also throws exceptions if there is an XML issue. I checked our code and this currently can happen when you have an empty document since there is no valid XML in it. We'll update code for the next build to not run validation if the document is empty.

You don't need to do anything with the semantic parser service. Just always leave it on.

Again these exceptions will occur if there is "bad" XML whenever if looks at the document. We catch them so they don't bubble up and log syntax errors. So you can ignore them if you have break on exception active.


Actipro Software Support

The latest build of this product (v2020.1 build 0400) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.