More in this section
Forums / Developing with Sitefinity / Locked RelatedImage throws System.Reflection.TargetInvocationException

Locked RelatedImage throws System.Reflection.TargetInvocationException

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
1 posts, 0 answered
  1. Kris
    Kris avatar
    16 posts
    24 Sep 2012
    27 Jul 2016
    Link to this post

    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.

1 posts, 0 answered