Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Edgar Rasquin 326 posts 925 karma points
    Jul 26, 2018 @ 13:59
    Edgar Rasquin
    0

    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:

    enter image description here

    Any ideas why I cannot GetPropertyValue in this example?

    Thanks a lot

  • Derek 17 posts 71 karma points
    Jul 26, 2018 @ 14:26
    Derek
    0

    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?

     if (sponsorItem.HasProperty("sponsorImage") && sponsorItem.HasValue("sponsorImage"))
     {
         var image = sponsorItem.GetPropertyValue<IPublishedContent>("sponsorImage");
    
     }
    
  • Edgar Rasquin 326 posts 925 karma points
    Jul 26, 2018 @ 15:14
    Edgar Rasquin
    0

    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:

    enter image description here

    It sais, that there is no Definition for HasPropety or GetPropertyValue

    Very strange...

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jul 26, 2018 @ 15:20
    Nik
    101

    What happens if you change your foreach loop to this:

    foreach(IPublishedContent sponsorItem in sponsors)
    

    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.

  • Edgar Rasquin 326 posts 925 karma points
    Jul 26, 2018 @ 19:04
    Edgar Rasquin
    1

    Hi Nik,

    great! It did the job.

    Thank you very much.

    A nice evening everyone :)

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jul 26, 2018 @ 19:14
    Nik
    1

    No worries :-) Please it helped.

Please Sign in or register to post replies

Write your reply to:

Draft