Reading Custom Media Image property throws System.ArgumentException
I created custom Image in media which has some addition crop settings. I called this media type ArticleImage.
Now when I try to read it in a partial view I am getting System.ArgumentException with the following message
The value "Umbraco.Web.PublishedModels.ArticleImage" is not of type "Umbraco.Web.PublishedModels.Image" and cannot be used in this generic collection.
Parameter name: value
Here is how the media type and the data type look like
and the data type used for umbracoFile property
I am accessing it with an extension method I wrote
public static String GetImageCropUrl(this IPublishedContent content, String propertyAlias, String cropAlias)
{
if (content.HasProperty(propertyAlias))
{
var umbHelper = Umbraco.Web.Composing.Current.UmbracoHelper;
var propValue = content.GetProperty(propertyAlias).GetSourceValue();
var media = umbHelper.Media(propValue);
return media?.GetCropUrl(cropAlias);
}
return null;
}
public static String GetImageUrl(this IPublishedContent content, String propertyAlias)
{
if (content.HasProperty(propertyAlias))
{
var umbHelper = Umbraco.Web.Composing.Current.UmbracoHelper;
var propValue = content.GetProperty(propertyAlias).GetSourceValue();
return umbHelper.Media(propValue)?.Url;
}
return null;
}
I am getting exception in views where I am not eve trying to get the image crop path with extension method.
For example I have document type Article which has a property of MediaPicker which is set to only pick ArtcleImage media and when I loop through children of parent of Artcle document I am getting the exception I mentioned above
Reading Custom Media Image property throws System.ArgumentException
I created custom Image in media which has some addition crop settings. I called this media type ArticleImage.
Now when I try to read it in a partial view I am getting System.ArgumentException with the following message
The value "Umbraco.Web.PublishedModels.ArticleImage" is not of type "Umbraco.Web.PublishedModels.Image" and cannot be used in this generic collection. Parameter name: value
I tried using
instead of default
but I am still getting the same exception, like there is something wrong with Umbraco8 and custom media image type.
Any idea how to resolve this?
what does your media type look like, and how are you trying to output it?
Hi,
Here is how the media type and the data type look like
and the data type used for umbracoFile property
I am accessing it with an extension method I wrote
I am getting exception in views where I am not eve trying to get the image crop path with extension method. For example I have document type Article which has a property of MediaPicker which is set to only pick ArtcleImage media and when I loop through children of parent of Artcle document I am getting the exception I mentioned above
is working on a reply...