Locked RelatedImage throws System.Reflection.TargetInvocationException
I have a Dynamic Module that has a related image field. Once the dynamic content item is published, if someone has accidentally locked the related image in the Image Library (usually using the back button) whenever I try to get the image to get the url for the widget I get a System.Reflection.TargetInvocationException.
public static string GetRelatedImageLink(this DynamicContent dynamicContent, string fieldName) Image image = dynamicContent.GetRelatedItems<Image>(fieldName).SingleOrDefault(); if (image != null) return image.ResolveMediaUrl(); return string.Empty;