Diagram serialization and GetNodeUniqueId receiving a node null

3 posts, 0 answers
  1. Thomas
    Thomas avatar
    4 posts
    Member since:
    Apr 2016

    Posted 11 Jul Link to this post


    I'm having the following issue with the Serialization process in the diagram:

    When I save the first time, it works great. (I can reload the layout several times and it works perfectly: my items go back to their saved positions)

    However, if I saveLayout, then LoadLayout, the next time I'm going to call SaveLayout will fail because node is null in the GetNodeUniqueId override.

    Any idea what could cause this? Thanks!

    public class NodeViewModel : NodeViewModelBase
    public class DiagramViewModel : SerializableGraphSourceBase<NodeViewModel, LinkViewModel>
    public override string GetNodeUniqueId(NodeViewModel node)
               if (node == null)
                   return string.Empty; // Should not happen (but happens on a saveLayout after a LoadLayout)
               return node.ID;
    public override NodeViewModel DeserializeNode(IShape shape, SerializationInfo info)
                NodeViewModel nodeViewModel = InternalItems.FirstOrDefault(p => p.DialogInfo.Tag == info["NodeUniqueIdKey"].ToString());
                if (nodeViewModel == null)
                    return null;
                string position = info["Position"].ToString();
                string[] arr = position.Split(';');
                nodeViewModel.Position = new Point(float.Parse(arr[0], CultureInfo.InvariantCulture), float.Parse(arr[1], CultureInfo.InvariantCulture));
                return nodeViewModel;

  2. Thomas
    Thomas avatar
    4 posts
    Member since:
    Apr 2016

    Posted 11 Jul in reply to Thomas Link to this post

    In simpler words, if I do :

    string xml = diagram.Save();
    xml = diagram.Save();

    The second Save call with call the GetNodeUniqueId with node param being null. (the first call being fine)





  3. DevCraft R3 2016 release webinar banner
  4. Martin
    Martin avatar
    1042 posts

    Posted 13 Jul Link to this post

    Hi Thomas,

    Without your implementation I cannot be sure what is causing the issue. However, it is possible to come from the override of the DeserializeNode() method of the graph source. You can double check if the method always returns a valid shape, instead of null. Note that DeserializeNode() is called for each shape loaded with the Load() method of the diagram.

    If this doesn't help you can post a runnable code that isolates your implementation so I can test it on my side. Or you can open a new support ticket where you can attach .zip file with a project.

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top