Skip to content
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

Closed
markoliver288 opened this issue Jun 19, 2020 · 6 comments
Closed

Deserialising a LayoutDocumentFloatingWindow gives XML error #167

markoliver288 opened this issue Jun 19, 2020 · 6 comments

Comments

@markoliver288
Copy link

When deserialising this saved layout:

<?xml version=""1.0"" encoding=""utf-16""?>
<LayoutRoot>
  <RootPanel Orientation=""Horizontal"">
    <LayoutDocumentPaneGroup Orientation=""Vertical"">
      <LayoutDocumentPane Id=""510dd237-81be-4b7d-acbf-97173c64122f"">
        <LayoutDocument Title=""Test Mymenu 1"" IsSelected=""True"" ContentId=""TestMymenu"" LastActivationTimeStamp=""11/20/2019 16:55:31"" />
      </LayoutDocumentPane>
      <LayoutDocumentPane Id=""e08ee504-1b6c-4c14-9987-ee6ea0f8d03e"">
        <LayoutDocument Title=""Mymenu 1"" IsSelected=""True"" ContentId=""Mymenu"" LastActivationTimeStamp=""11/20/2019 16:55:03"" />
      </LayoutDocumentPane>
      <LayoutDocumentPane>
        <LayoutDocument Title=""Test Mymenu 2"" IsSelected=""True"" ContentId=""TestMymenu"" FloatingLeft=""115"" FloatingTop=""32"" FloatingWidth=""136"" FloatingHeight=""39"" LastActivationTimeStamp=""11/20/2019 16:49:17"" />
      </LayoutDocumentPane>
    </LayoutDocumentPaneGroup>
  </RootPanel>
  <TopSide />
  <RightSide />
  <LeftSide />
  <BottomSide />
  <FloatingWindows>
    <LayoutDocumentFloatingWindow>
      <LayoutDocument Title=""Dev AIX 1"" IsSelected=""True"" IsLastFocusedDocument=""True"" ContentId=""DevAix"" FloatingLeft=""2573"" FloatingTop=""291"" FloatingWidth=""1079"" FloatingHeight=""769"" LastActivationTimeStamp=""11/20/2019 16:55:44"" PreviousContainerId=""e08ee504-1b6c-4c14-9987-ee6ea0f8d03e"" PreviousContainerIndex=""1"" />
    </LayoutDocumentFloatingWindow>
    <LayoutDocumentFloatingWindow>
      <LayoutDocument Title=""Gorgias Browser"" IsSelected=""True"" ContentId=""Gorgias Browser:https://sitters.gorgias.io/"" FloatingLeft=""2568"" FloatingTop=""8"" FloatingWidth=""1141"" FloatingHeight=""750"" LastActivationTimeStamp=""11/20/2019 16:55:40"" PreviousContainerId=""e08ee504-1b6c-4c14-9987-ee6ea0f8d03e"" PreviousContainerIndex=""1"" />
    </LayoutDocumentFloatingWindow>
    <LayoutDocumentFloatingWindow>
      <LayoutDocument Title=""Fees And Rates"" IsSelected=""True"" ContentId=""FeesAndRates"" FloatingLeft=""1950"" FloatingTop=""9"" FloatingWidth=""605"" FloatingHeight=""866"" LastActivationTimeStamp=""11/20/2019 16:55:31"" PreviousContainerId=""510dd237-81be-4b7d-acbf-97173c64122f"" PreviousContainerIndex=""1"" />
    </LayoutDocumentFloatingWindow>
  </FloatingWindows>
  <Hidden />
</LayoutRoot>

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.

@markoliver288
Copy link
Author

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.
AvalonDock_Layout_1.txt

@Dirkster99
Copy link
Owner

Dirkster99 commented Jun 19, 2020

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 LayoutDocumentFloatingWindow without LayoutDocumentPaneGroup and LayoutDocumentPane while version 4.0 expects this to be present now.

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?

@markoliver288
Copy link
Author

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.

@Dirkster99
Copy link
Owner

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)?

@markoliver288
Copy link
Author

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.

@Dirkster99
Copy link
Owner

Looks pretty nice to me - thanx for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants