A media picker returns an IEnumerable<IPublishedContent> when processed by Umbraco-Core-Property-Value-Converters. So change var personaImage = empathyMap.GetPropertyValue<IPublishedContent>("personaImage") by var personaImage = empathyMap.GetPropertyValue<IEnumerable<IPublishedContent>>("personaImage").FirstOrDefault()
Cannot fetch media in Umbraco 7.5.3
Hey,
I've got a new install of Umbraco 7.5.3 and I keep getting an "Object reference not set to an instance of an object" error when I try to render media.
Normally I fetch it the following way:
This doesn't work for some reason, but this does:
That doesn't help me much when I have to loop through images, though.
Any ideas?
Hi Marshmeryl
How do you want to loop through images? What datatype are you using?
You can use this code in loop:
Can you show all you razor code and what exactly do you need?
Thanks,
Alex
Thanks for the fast response.
This bit:
Doesn't work outside of a loop either :/
Regarding the loops, here's what I do:
I have nested content, which I fetch like this:
Then:
The string is fine, image throws the null reference error.
Try this code:
Still null :/
Is it right property alias - "personaImage"?
Is it media picker property editor?
Can you look at /app_data/umbraco.config - find needed node and look, please, how this field looks in xml?
Thanks,
Alex
It's the correct property alias and yes, media picker editor.
Here's what the umbraco.config file says:
Interesting, and do you have media items with these ids in the system?
Are you using "Umbraco-Core-Property-Value-Converters"?
https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters
Yes, the two media items I have are exactly with those id's.
Also yes.
Ended up going in the Developer section and changing the data type from "Media Picker" to "Legacy Media Picker" and now it works...
Thanks for taking the time to try and help me!
A media picker returns an
IEnumerable<IPublishedContent>
when processed by Umbraco-Core-Property-Value-Converters. So changevar personaImage = empathyMap.GetPropertyValue<IPublishedContent>("personaImage")
byvar personaImage = empathyMap.GetPropertyValue<IEnumerable<IPublishedContent>>("personaImage").FirstOrDefault()
is working on a reply...