Copied to clipboard

Flag this post as spam?

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


  • bh 444 posts 1544 karma points
    Jun 10, 2021 @ 18:19
    bh
    0

    ImageCropper MediaItem thinks it's null

    var fbimage = Model.Value("FacebookImage") == null ? null : Model.Value<IPublishedContent>("FacebookImage").GetCropUrl(1200,630);
    

    Model.Value("FacebookImage") is not null, but I get the below error on the line of code above.

    Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: mediaItem

    What am I missing?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 10, 2021 @ 19:26
    Dan Diplo
    0

    What version of Umbraco are you using?

  • bh 444 posts 1544 karma points
    Jun 10, 2021 @ 19:41
    bh
    0

    8.14

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 10, 2021 @ 20:00
    Dan Diplo
    1

    If you are using the new Media Picker 3 then it no longer returns IPublishedContent but, instead, a new type called MediaWithCrops that then has a property called MediaItem that contains the actual published media content.

    So you'd need to change your code to be something like this (not 100% sure):

    var fbimage = Model.Value("FacebookImage") == null ? null : Model.Value<MediaWithCrops>("FacebookImage").GetCropUrl(1200,630);

    I've raised this as an issue as it feels like a breaking change, but that is the way it is now. See https://github.com/umbraco/Umbraco-CMS/issues/10397 for the back story.

  • bh 444 posts 1544 karma points
    Jun 10, 2021 @ 20:20
    bh
    0

    Thanks for the info. Unfortunately MediaWithCrops doesn't have GetCropUrl. I despise crop aliases! I much prefer specifying the crop in code. I started out using cropaliases in Umbraco, and adding/maintaining them was so much more laborious than just specifying .GetCropUrl(W,H) when adding an image to my template.

  • bh 444 posts 1544 karma points
    Jun 10, 2021 @ 20:28
    bh
    101

    @DanDiplo you were VERY close. Thanks for pointing me in the right direction!!

    This works:

    var fbimage = Model.Value("FacebookImage") == null ? null : Model.Value<MediaWithCrops>("FacebookImage").MediaItem.GetCropUrl(1200,630);
    
Please Sign in or register to post replies

Write your reply to:

Draft