Dirkster99 / AvalonDock

Our own development branch of the well known WPF document docking library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AvalonDock.LayoutRoot doesn't know how to deserialize...

aelij opened this issue · comments

When trying to deserialize a layout, the following exception is thrown:

System.InvalidOperationException: There is an error in XML document (17, 14).
 ---> System.ArgumentException: AvalonDock.LayoutRoot doesn't know how to deserialize 
   at Xceed.Wpf.AvalonDock.Layout.LayoutRoot.ReadElement(XmlReader reader)
   at Xceed.Wpf.AvalonDock.Layout.LayoutRoot.ReadElementList(XmlReader reader, Boolean isFloatingWindow)
   at Xceed.Wpf.AvalonDock.Layout.LayoutRoot.ReadXml(XmlReader reader)
   at System.Xml.Serialization.XmlSerializationReader.ReadSerializable(IXmlSerializable serializable, Boolean wrappedAny)
   at System.Xml.Serialization.XmlSerializationReader.ReadSerializable(IXmlSerializable serializable)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLayoutRoot.Read1_LayoutRoot()
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
   at Xceed.Wpf.AvalonDock.Layout.Serialization.XmlLayoutSerializer.Deserialize(TextReader reader)

Layout XML:

<LayoutRoot>
  <RootPanel Orientation="Horizontal">
    <LayoutAnchorablePane Id="3305ae34-d029-44f2-a5f1-de32a4e7c7bf" Name="Documents" DockWidth="200" />
    <LayoutDocumentPane>
      <LayoutDocument IsSelected="True" IsLastFocusedDocument="True" LastActivationTimeStamp="01/27/2020 07:52:18" />
      <LayoutDocument />
    </LayoutDocumentPane>
  </RootPanel>
  <TopSide />
  <RightSide />
  <LeftSide>
    <LayoutAnchorGroup PreviousContainerId="3305ae34-d029-44f2-a5f1-de32a4e7c7bf">
      <LayoutAnchorable CanHide="False" AutoHideWidth="200" AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Documents" ContentId="DocumentTree" CanClose="False" CanFloat="False" />
    </LayoutAnchorGroup>
  </LeftSide>
  <BottomSide />
</LayoutRoot>

Looking at the stack on first-chance exception, the xmlReader is at EOF (NodeType=None) so the following method should check that condition:

private object ReadElement(XmlReader reader)

Note the same code worked just fine in the WPF Toolkit version.

Hi, thanks for your feedback. Just to clearify your change request. Are you suggesting to change the 2nd if statement in private object ReadElement(XmlReader reader) as shown below:

if (reader.NodeType == XmlNodeType.EndElement || reader.NodeType == XmlNodeType.None)
{
    return null;
}

Please let me know if this should work for you. Thanx Dirk

Hi,

I cannot directly verify your exakt problem unless you give me a Layout that I can use with a test application in the repository (eg. Save a sample layout with MLibTest).

Nethertheless, I've tried to triangulate your problem and found a possible fix in this branch:
Fix_Issue_111

Would you please test this branch and let me know whether this works for you? It is important that you test more than the error case because I received errors (when loading a layout) about the PreviousContainerId not being resolvable and I am not sure whether thats because:

  1. I manipulated the layout manually or
  2. whether this is a direct problem with the current fix candidate?

@Dirkster99 Sorry for not replying earlier. Your fix works, thanks a lot!! ❤️

It was @scdmitryvodich fix that worked I was not able to pin this one (sadly) - so I only released it but thanks for the good feedback :-)