Locked RelatedImage throws System.Reflection.TargetInvocationException - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Locked RelatedImage throws System.Reflection.TargetInvocationException

  • 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;

    Does anyone have a better way to get the related images url? I would it rather just not get the url and not show anything that throw a controller error that hoses the entire widget in stead of not displaying the image.