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?
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?
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:
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:
Has anyone experienced the same problem? Is this a bug?
Thanks, Justin
Hi Justin,
What version of Umbraco are you using?
Try to use this syntax:
Thanks,
Alex
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:
Before saving the media item, the ImageCropDataSet has:
After saving the media it has:
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
is working on a reply...