I'd check all the 'sponsors' actually have a 'sponsor image' value set. As you are trying to reference the image value without first checking if there is even an image assigned you could get and 'Object reference not set to an instance of an object' error.
If you try adding in a check first do you still get an error?
if (sponsorItem.HasProperty("sponsorImage") && sponsorItem.HasValue("sponsorImage"))
{
var image = sponsorItem.GetPropertyValue<IPublishedContent>("sponsorImage");
}
thanks for your advise.
I tried but it does not solve my problem.
Actually I dont get the error 'Object reference ....'
In my case it seems strange that in Visual Studio I do not get the GetPropertyValue in intelliSense:
It sais, that there is no Definition for HasPropety or GetPropertyValue
Troubel getting image from nestedContent
Hi there,
I am experiencing trouble trying to render an Image from within nested content type. I use this method quite a lot and I never got this error before:
Any ideas why I cannot GetPropertyValue in this example?
Thanks a lot
Hi Edgar,
I'd check all the 'sponsors' actually have a 'sponsor image' value set. As you are trying to reference the image value without first checking if there is even an image assigned you could get and 'Object reference not set to an instance of an object' error.
If you try adding in a check first do you still get an error?
Hi Derek,
thanks for your advise. I tried but it does not solve my problem.
Actually I dont get the error 'Object reference ....' In my case it seems strange that in Visual Studio I do not get the GetPropertyValue in intelliSense:
It sais, that there is no Definition for HasPropety or GetPropertyValue
Very strange...
What happens if you change your foreach loop to this:
I looks like you have Models Builder enabled and some sort of casting is attempting to happen. This might force it not to do this.
Hi Nik,
great! It did the job.
Thank you very much.
A nice evening everyone :)
No worries :-) Please it helped.
is working on a reply...