Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm getting "Cannot perform runtime binding on a null reference" when the following code is run.
var mediaItem = Umbraco.TypedMedia(CurrentPage.coverImage).OfType<Image>();
CurrentPage.coverImage is a Media Picker that returns the image ID.
That said, when I manually enter the ID:
var mediaItem = Umbraco.TypedMedia(1101).OfType<Image>();
Everything works out fine.
Any thoughts are appreciated, and thanks in advance!
Hi Dan
Welcome to our friendly forum!!!
1) You are not in the spam query anymore
2) Try this code:
var mediaItem = Umbraco.TypedMedia(Umbraco.AssignedContentItem.GetPropertyValue<int>("coverImage")).OfType<Image>();
CurrentPage.coverImage - dynamically typed, try to avoid dynamic types.
Thanks,
Alex
Thanks for your help!
I suppose it would've been more helpful to mention I was trying to use it with GetCropUrl.
This also seemed to work for GetCropUrl:
coverImage = Model.Content.GetPropertyValue<IPublishedContent>("coverImage")
Without needing to use Umbraco.TypedMedia.
I'm very new to C# and Umbraco, so I'm not sure what the benefits are over one method or the other, but I'm definitely avoiding dynamic types from here on!
Thanks again!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Cannot perform runtime binding on a null reference when passing Media Picker field into Umbraco.TypedMedia
I'm getting "Cannot perform runtime binding on a null reference" when the following code is run.
CurrentPage.coverImage is a Media Picker that returns the image ID.
That said, when I manually enter the ID:
Everything works out fine.
Any thoughts are appreciated, and thanks in advance!
Hi Dan
Welcome to our friendly forum!!!
1) You are not in the spam query anymore
2) Try this code:
CurrentPage.coverImage - dynamically typed, try to avoid dynamic types.
Thanks,
Alex
Thanks for your help!
I suppose it would've been more helpful to mention I was trying to use it with GetCropUrl.
This also seemed to work for GetCropUrl:
Without needing to use Umbraco.TypedMedia.
I'm very new to C# and Umbraco, so I'm not sure what the benefits are over one method or the other, but I'm definitely avoiding dynamic types from here on!
Thanks again!
is working on a reply...