From eecb6c3b6edd49ca133e0207bf8e299cb11fdf8c Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Sat, 23 May 2020 10:36:39 +0100 Subject: [PATCH] Fix #108 - Parent nodes can be null when items are put in the trash. fixes the find methods, which are called to get a parent item, but when you trash a item - its parent is set to null :frowning: --- .../Serializers/ContentSerializer.cs | 10 +++++++--- uSync8.ContentEdition/Serializers/MediaSerializer.cs | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/uSync8.ContentEdition/Serializers/ContentSerializer.cs b/uSync8.ContentEdition/Serializers/ContentSerializer.cs index 6856ef5e..27903587 100644 --- a/uSync8.ContentEdition/Serializers/ContentSerializer.cs +++ b/uSync8.ContentEdition/Serializers/ContentSerializer.cs @@ -325,9 +325,13 @@ protected override IContent CreateItem(string alias, ITreeEntity parent, string protected override IContent FindItem(int id) { var item = contentService.GetById(id); - if (!this.nameCache.ContainsKey(id)) - this.nameCache[id] = new Tuple(item.Key, item.Name); - return item; + if (item != null) + { + if (!this.nameCache.ContainsKey(id)) + this.nameCache[id] = new Tuple(item.Key, item.Name); + return item; + } + return null; } protected override IContent FindItem(Guid key) diff --git a/uSync8.ContentEdition/Serializers/MediaSerializer.cs b/uSync8.ContentEdition/Serializers/MediaSerializer.cs index 3ed05f82..f16b72bb 100644 --- a/uSync8.ContentEdition/Serializers/MediaSerializer.cs +++ b/uSync8.ContentEdition/Serializers/MediaSerializer.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; using System.Security.Cryptography; using System.Xml.Linq; @@ -182,9 +183,13 @@ protected override IMedia CreateItem(string alias, ITreeEntity parent, string it protected override IMedia FindItem(int id) { var item = mediaService.GetById(id); - if (!this.nameCache.ContainsKey(id)) - this.nameCache[id] = new Tuple(item.Key, item.Name); - return item; + if (item != null) + { + if (!this.nameCache.ContainsKey(id)) + this.nameCache[id] = new Tuple(item.Key, item.Name); + return item; + } + return null; }