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 156 karma points
    May 17, 2019 @ 20:21
    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 2141 posts 14344 karma points MVP 8x c-trib
    May 17, 2019 @ 21:57
    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 156 karma points
    May 17, 2019 @ 22:07
    Jose Badia
    0

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

    var bannerImage = Model.Content.GetPropertyValue<IPublishedContent>("bannerImage");
    
  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    May 18, 2019 @ 08:11
    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 156 karma points
    May 20, 2019 @ 19:05
    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 2141 posts 14344 karma points MVP 8x c-trib
    May 20, 2019 @ 21:22
    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 156 karma points
    May 20, 2019 @ 21:36
    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