Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jose Badia 13 posts 154 karma points
    1 week ago
    Jose Badia
    0

    GetPropertyValue error on image after upgrade

    After upgrading from 7.6.0 to 7.14.0, I am now getting an "Object reference not set to an instance" error when trying to get an ImagePicker property.

            @if (Model.Content.HasValue("bannerImage"))
            {
                var temp = Model.Content.GetPropertyValue("bannerImage");
                <img src="@Umbraco.TypedMedia(Model.Content.GetPropertyValue("bannerImage")).Url" />
            }
    

    I tried changing EnablePropertyValueConverters to false, and that seemed to fix this particular code, but it broke GetPropertyValue calls for other properties. Any suggestions as to what might be causing this and how to fix it?

  • Marc Goodson 854 posts 5576 karma points MVP 3x c-trib
    7 days ago
    Marc Goodson
    0

    Hi Jose

    With PropertyValueConverters enabled then you should be able to do this:

     @if (Model.Content.HasValue("bannerImage"))
            {
                var bannerImage = Model.Content.GetPropertyValue<IPublishedContent>("bannerImage");
                <img src="@bannerImage.Url" />
            }
    

    Essentially the property value converter for a single media picker will do the whole Umbraco.TypedMedia step for you...

    Regards

    Marc

  • Jose Badia 13 posts 154 karma points
    7 days ago
    Jose Badia
    0

    Thanks Marc. The error occurs at GetPropertyValue. This line fails as well.

    var bannerImage = Model.Content.GetPropertyValue<IPublishedContent>("bannerImage");
    
  • Marc Goodson 854 posts 5576 karma points MVP 3x c-trib
    7 days ago
    Marc Goodson
    0

    Hi Jose

    Have you rebuilt your Examine InternalIndex since the upgrade?

    and if you find the image in the backoffice media section and 'save' it again - does it work?

    regards

    Marc

  • Jose Badia 13 posts 154 karma points
    4 days ago
    Jose Badia
    0

    Thanks again, Marc. I hit save on the image's media record. I also tried rebuilding the index by deleting the files in Internal\Index. Neither of these actions seemed to make a difference.

  • Marc Goodson 854 posts 5576 karma points MVP 3x c-trib
    4 days ago
    Marc Goodson
    0

    Hi Jose

    Is it a single Media Picker or Multiple Media Picker?

    If multiple then...

    var bannerImage = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("bannerImage").FirstOrDefault();
    

    also does it blow up on

    var mediaId = Model.Content.GetPropertyValue<int>("bannerImage");
    

    ?

    regards

    Marc

  • Jose Badia 13 posts 154 karma points
    4 days ago
    Jose Badia
    0

    It is a single Umbraco.MediaPicker (not MediaPicker2). It blows up with GetPropertyValue<int> as well.

Please Sign in or register to post replies

Write your reply to:

Draft