-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deserialising a LayoutDocumentFloatingWindow gives XML error #167
Comments
This can easily be replicated by dropping the attached file (rename from .txt. to .config) in the bin directory of the TestApp and choosing to "Load" the "Layout_1" config. |
Hi, the serialization/deserialization of Floating Document Windows between 3.6.2 and 4.0 appears to be incompatible (unfortunately there is no layout upgrade function or anything like this). The feature should work if you could initialize your layout with 4.0, save it, and then reload it with the same version. The change (which I am realizing now) is that version 3.6.2 serialized Here is the layout from my editor Edi which happens to use version 4.0: ...
<FloatingWindows>
<LayoutDocumentFloatingWindow>
<LayoutDocumentPaneGroup Orientation="Horizontal" FloatingWidth="794" FloatingHeight="652" FloatingLeft="45.6" FloatingTop="126.8">
<LayoutDocumentPane DockWidth="1.47295856006761*" DockHeight="0.65661252900232*" FloatingWidth="794" FloatingHeight="652" FloatingLeft="45.6" FloatingTop="126.8">
<LayoutDocument Title="AvalonDock_Layout_1 (1).txt" IsSelected="True" ContentId="X:\AvalonDock_Layout_1 (1).txt" ToolTip="X:\AvalonDock_Layout_1 (1).txt" FloatingLeft="45.6" FloatingTop="126.8" FloatingWidth="794" FloatingHeight="652" LastActivationTimeStamp="06/19/2020 18:18:39" PreviousContainerId="e138cfab-ee78-46d6-9e01-8cd8c3e94c67" PreviousContainerIndex="0" />
</LayoutDocumentPane>
</LayoutDocumentPaneGroup>
</LayoutDocumentFloatingWindow>
</FloatingWindows>
... This issue seems to be caused by the 2 versions of ReadXml in LayoutDocumentFloatingWindow: I am not sure if we should attempt to fix this as a backward compatible upgrade path - what do you think? |
Thanks for that. Very useful. Because this was a blocking issue for me, I have made a "backward compatability" fix for us. When we read the XML in from our saved layouts, we insert these missing leafs of the XML, and then we can deserialise it. I think its not a big enough issue to warrant fixing, but it is a breaking change, so should be described on the upgrade documentation for v4. Thanks for your help. |
Yes, now that I know about it I can document it here. Would you be able to share your "backward compatability" fix with others so they can use it if they run into the same issue (I would be happy to add a code snippet or such into the docs)? |
Its not pretty code, but it does work: /// <summary>Some stored layouts may not be compatible with the version required now. So update it.</summary>
/// <param name="layoutSchema">The layout of the displays</param>
/// <returns>The <see cref="string"/> that contains adjusted layout</returns>
private string AddBackwardsCompatabilityTagsIntoDisplayLayout( string layoutSchema )
{
XDocument xLayout = XDocument.Parse( layoutSchema );
XElement root = xLayout.Root;
var allInvalidDocuments = root.Elements( @"FloatingWindows" )
.Elements( @"LayoutDocumentFloatingWindow" )
.Elements( @"LayoutDocument" ).ToList();
if ( allInvalidDocuments.Any() )
{
var newFloatingWindowsRoot = new XElement( "FloatingWindows" );
foreach ( XElement invalidDocumentItem in allInvalidDocuments )
{
XElement newParentParentParent = new XElement( "LayoutDocumentFloatingWindow" );
XElement newParentParent = new XElement( "LayoutDocumentPaneGroup" );
newParentParent.SetAttributeValue( "Orientation", "Horizontal" );
XElement newParent = new XElement( "LayoutDocumentPane" );
newFloatingWindowsRoot.Add( newParentParentParent );
newParentParentParent.Add( newParentParent );
newParentParent.Add( newParent );
newParent.Add( invalidDocumentItem );
}
//Now put them in the document correctly.
xLayout.Root.Element( @"FloatingWindows" ).ReplaceWith( newFloatingWindowsRoot );
}
string adjustedLayout = $@"{xLayout.Declaration}{Environment.NewLine}{xLayout}";
return adjustedLayout;
} Because of this change with LayoutDocuments, we had to tweak some of our templates, and any code that referenced LayoutDocuments required checking too. All of that code is bespoke to us though, so no point sharing here. |
Looks pretty nice to me - thanx for sharing |
When deserialising this saved layout:
I get the error "There is an error in xml document (23,7)"
This is the start of the LayoutDocumentFloatingWindow data.
I have gone back to 3.6.2 and it works. It stops working at version 4.0.0
Looking at the code, there is significant difference in this area between the versions.
The text was updated successfully, but these errors were encountered: