Copied to clipboard

Flag this post as spam?

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


  • Justin Neville 6 posts 26 karma points
    Oct 29, 2016 @ 15:55
    Justin Neville
    0

    Unable to get value for media property 'umbracoFile' after saving media

    Hi all,

    Has anyone else come across a problem in Umbraco 7.5.3 where you can no longer access the umbracoFile property of an image after saving the media?

    If I upload an image I can access the URL as expected using:

    var media = Umbraco.TypedMedia(1510);
    var url = media.GetPropertyValue<string>("umbracoFile");
    

    But, if I then save the media item via the backend (perhaps to replace the image etc), I can no longer get the URL by querying for the umbracoFile property as I get an exception:

    [ArgumentNullException: Value cannot be null.
    Parameter name: source]
       System.Linq.Enumerable.Any(IEnumerable`1 source) +4356218
       Umbraco.Web.Models.ImageCropDataSet.ToString() +18
       Umbraco.Core.ObjectExtensions.TryConvertTo(Object input, Type destinationType) +358
       Umbraco.Core.ObjectExtensions.TryConvertTo(Object input) +71
       Umbraco.Web.PublishedPropertyExtension.GetValue(IPublishedProperty property, Boolean withDefaultValue, T defaultValue) +171
       Umbraco.Web.PublishedContentExtensions.GetPropertyValue(IPublishedContent content, String alias, Boolean recurse, Boolean withDefaultValue, T defaultValue) +82
       Umbraco.Web.PublishedContentExtensions.GetPropertyValue(IPublishedContent content, String alias) +59
    

    Has anyone experienced the same problem? Is this a bug?

    Thanks, Justin

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Oct 29, 2016 @ 16:13
    Alex Skrypnyk
    0

    Hi Justin,

    What version of Umbraco are you using?

    Try to use this syntax:

    var url = media.Url;
    

    Thanks,

    Alex

  • Justin Neville 6 posts 26 karma points
    Oct 30, 2016 @ 14:34
    Justin Neville
    0

    Hi Alex,

    I'm using Umbraco 7.5.3.

    Yes, it does work when accessing the media.Url property. I just find it odd that saving the media item can cause different behaviour when getting the URL using the umbracoFile value directly.

    Debugging through, if I use this code it returns an ImageCropDataSet:

    var url = media.GetPropertyValue("umbracoFile");
    

    Before saving the media item, the ImageCropDataSet has:

    Crops = 0
    FocusPoint = null
    

    After saving the media it has:

    Crops = null
    FocusPoint = 0.5/0.5
    

    So, the ToString() on the ImageCropDataSet is not handling the fact that the Crops is null and throwing the exception.

    At least I have a workaround but just wondered if it was a bug or intended behaviour?

    Thanks, Justin

Please Sign in or register to post replies

Write your reply to:

Draft