diff --git a/Helper/entity.partial.cs b/Helper/entity.partial.cs index 1deaaa6..6e0b92d 100644 --- a/Helper/entity.partial.cs +++ b/Helper/entity.partial.cs @@ -33,7 +33,13 @@ public static string GetFormattedAttribValue(this Entity entity, string attribut { try { - if (null != entity && entity.Attributes.Contains(attributeLogicalName)) + // Guard on the collection being indexed, not on Attributes. An attribute can + // be present with no formatted value beside it, and then this indexer throws. + // associatedentitytypecode is the one that bites: Dataverse only sends a + // formatted value for it when it can resolve the table, so a template whose + // table was deleted, or that came from another organization, arrives as + // 'none' with nothing formatted and takes the whole load down with it. + if (null != entity && entity.FormattedValues.Contains(attributeLogicalName)) { return entity.FormattedValues[attributeLogicalName]; }