diff --git a/src/JsonLD/Core/JsonLdApi.cs b/src/JsonLD/Core/JsonLdApi.cs index 065e952..60d61b8 100644 --- a/src/JsonLD/Core/JsonLdApi.cs +++ b/src/JsonLD/Core/JsonLdApi.cs @@ -1663,9 +1663,14 @@ private static void RemoveDependents(IDictionary em , string id) { // get embed keys as a separate array to enable deleting keys in map - foreach (string id_dep in embeds.Keys) + List embedsKeys = new List(embeds.Keys); + foreach (string id_dep in embedsKeys) { - JsonLdApi.EmbedNode e = embeds[id_dep]; + JsonLdApi.EmbedNode e; + if (!embeds.TryGetValue(id_dep, out e)) + { + continue; + } JToken p = !e.parent.IsNull() ? e.parent : new JObject(); if (!(p is JObject)) {