Copied to clipboard

Flag this post as spam?

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


  • Jerritte Couture 15 posts 97 karma points
    Feb 11, 2017 @ 00:57
    Jerritte Couture
    0

    Value cannot be null. Parameter name: mediaItem

    I'm running Umbraco 7.5.9 and uCommerce 7.0.5.16060 (planning to update within a week or two). We just noticed today that four of our client's category pages (or sub-category pages) are throwing the following error, and we cannot track down what's causing it. Currently, I'm unsure of whether this is an Umbraco issue or a uCommerce issue...though it looks like it may be an Umbraco issue. This started to occur after we updated Umbraco to the latest version earlier this week.

    If anyone can provide some insight into this, it would be greatly appreciated!

    [If you right-click the image and open in a new window, you'll be able to read the error text.]

    Error -- Value cannot be null. Parameter name: mediaItem

  • Jerritte Couture 15 posts 97 karma points
    Feb 11, 2017 @ 04:49
    Jerritte Couture
    0

    I've located what's causing this, but I haven't been able to determine how to check whether the mediaSource.GetCropUrl is null or not. This is the source of the error:

    if (!string.IsNullOrEmpty(product.GetPropertyValue<string>("MainProductImage")))
                    {
                        //var media = ObjectFactory.Instance.Resolve<IImageService>().GetImage(product.ThumbnailImageMediaId).Url;
                        var media = product.GetPropertyValue<string>("MainProductImage");
                        var mediaSource = umbracoHelper.TypedMedia(media);
                        <a href="@url">
                            @*<img src="@mediaSource.GetCropUrl("umbracoFile", "store-product-medium")" class="main-image" />*@
                        </a>
                    }
                    else
                    {
                        <a href="@url">
                            <img class="main-image" src="~/umbraco/ucommerce/images/ui/image_not_found.jpg">
                        </a>
                    }
    

    Specifically, the issue is caused here:

    <img src="@mediaSource.GetCropUrl("umbracoFile", "store-product-medium")" class="main-image" />
    

    ...which is commented out above, since it's not working. I've tried to trap for the null reference like this, but it's not working either:

    if (!string.IsNullOrEmpty(mediaSource.GetCropUrl("umbracoFile", "store-product-medium")))
    
  • Jerritte Couture 15 posts 97 karma points
    Feb 11, 2017 @ 06:31
    Jerritte Couture
    101

    I'm still unsure as to why the if statement above didn't work, but using a try-catch does work. I'm posting this here in case it may help someone else who experiences this same issue:

                        try
                        {
                            <a href="@url">
                                <img src="@mediaSource.GetCropUrl("umbracoFile", "store-product-medium")" class="main-image" />
                            </a>
                        }
                        catch
                        {
                            <a href="@url">
                                <img class="main-image" src="~/umbraco/ucommerce/images/ui/image_not_found.jpg">
                            </a>
                        }
    
  • Stefano 61 posts 313 karma points c-trib
    Feb 11, 2017 @ 19:00
    Stefano
    0

    Hi Jerritte,

    Try something like

    @(mediaSource?.GetCropUrl("umbracoFile", "store-product-medium") ?? "/umbraco/ucommerce/images/ui/image_not_found.jpg")
    

    You'll need C#6. I think Umbraco also has an IfNullOrWhitespace() Extension method.

  • Jerritte Couture 15 posts 97 karma points
    Feb 12, 2017 @ 02:46
    Jerritte Couture
    0

    Stephano,

    That's using C# 6, so I can't use that yet.

  • Stefano 61 posts 313 karma points c-trib
    Feb 12, 2017 @ 10:17
    Stefano
    0

    I found upgrading is usually fast and straightforward, however here is the pre C#6 way:

    @(mediaSource != null ? mediaSource .GetCropUrl("umbracoFile", "store-product-medium") : "/umbraco/ucommerce/images/ui/image_not_found.jpg")
    
  • Jerritte Couture 15 posts 97 karma points
    Feb 17, 2017 @ 18:14
    Jerritte Couture
    0

    Stephano,

    Ah...that works, and is clearly more concise! I should have known that. :)

    Thanks!

  • Andreas Kaltenhuber 107 posts 286 karma points
    Apr 25, 2019 @ 09:12
    Andreas Kaltenhuber
    0

    I'm having the same issue. So this seems to be a BUG with NuCache. After a certain period my V8.0.1 website throws exactly this error.

    A workaround makes no sense, because the value and mediaitem does exists. Somehow the cache gets invalid.

    When i RELOAD NuCache from the Backend, the error is gone and the mediaItem "exists". I have to reload the cache several times a day.

    Are there any special settings regarding nucache we have to take care of during the server setup? The AppPool\name has sufficient rights on the folders.

    Thx in advance, Andreas

  • Kevin Blake 23 posts 45 karma points
    Apr 27, 2019 @ 10:39
    Kevin Blake
    0

    I've been getting this same problem with a new 8.0.1 install - it seems to happen after any AppPool restarts.

    1. View page, get the error: Value cannot be null. Parameter name: mediaItem
    2. Reload the in-memory / local file cache from the backend
    3. View page - works
    4. Recycle app pool
    5. View page, get the error: Value cannot be null. Parameter name: mediaItem

    Rinse and repeat. I'm keen on finding a better solution to this, as well.

  • Kevin Blake 23 posts 45 karma points
    Apr 30, 2019 @ 20:06
    Kevin Blake
    0

    Confirmed that this is resolved in 8.0.2 (at least, after recycling as listed above).

  • JoskerVemeulen 68 posts 262 karma points
    Jun 15, 2020 @ 17:27
    JoskerVemeulen
    0

    Instead of

    ImageUrl = item.HasValue("image") 
    

    We use

    ImageUrl = item.Value("image") != null
    

    And all is good! Umbraco 8.6

Please Sign in or register to post replies

Write your reply to:

Draft