ApplicationException during deserialization of toolbar layout

Bars for Windows Forms Forum

Posted 3 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 14.1.0320
Platform: .NET 4.0
Environment: Windows 10 (64-bit)
Avatar

Hi,

we stumbled upon a problem of the toolbar layout serialization. It took me a while to figure it out. Since we have the source code, we don't need a new build from you. I just wanted to let you know about the issue.

ApplicationException occured

An error occurred while loading the layout data:
The tag 'DockableToolBars' may not be parent to a 'DockedStateInfo' tag.

The root of the problem is a dynamic toolbar that is updated automatically. However the serializer doesn't know that and these dynamic commandos are serialized either way. When loading the layout, the deserializer checks if the command is known to the bar manager. If not the xml reader skips the element. And I think that is excactly the problem. In fact the reader does not skip the current element, but the next one.

Take a look at the method ValidateCommandName() in BarLayoutXmlSerializer.

So if all command links of the toolbar are not found, the deserializer only looks at the odd elements (1, 3, 5, ...). If the collection of the command links is an even number, that doesn't cause any trouble. He just skips the even elements, but we don't care about that. However if the collection has an uneven number, the exception is thrown.


Best regards, Tobias Lingemann.

Comments (5)

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

Hi Tobias,

Good find... since we call a "reader.Skip()" in that ValidateCommandName, it's reading an extra XML element that it shouldn't be.  To confirm with you, you just commented out that particular line and everything works properly since ValidateCommandName still returns a boolean indicating validation success, right?


Actipro Software Support

Posted 3 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

Correct, thats what I did. That solved this particulary issue. However I suppose you have more insights on whether or not there are other use cases. The method ValidateCommandName() is used in four places, but I only checked one (DockableToolbar). I just assumend the others would behave the same way.


Best regards, Tobias Lingemann.

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

Hi Tobias,

All three places ValidateCommandName is called seem to be called the same way.  But after examining it again, I wonder if we need to handle scenarios where there could be nested tags within the one being examined.  In that case, we'd need to likely skip over them.

Could you try changing that "reader.Skip()" line in ValidateCommandName to:

// If the current node is not empty...
if (!reader.IsEmptyElement) {
	// Store the depth and advance
	int depth = reader.Depth;
	reader.Read();

	// Loop while the depth is below the initial depth
	while ((!reader.EOF) && (reader.Depth > depth))
		reader.Read();
}

Please let me know if that works for your scenario.


Actipro Software Support

Posted 3 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

That works too. In my scenario the command links don't have any nested tags.


Best regards, Tobias Lingemann.

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

Hi Tobias,

Thanks, we've updated our code for the next maintenance release to match the above.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 9 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.