Copied to clipboard

Flag this post as spam?

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


  • Addison 5 posts 75 karma points
    Dec 18, 2019 @ 19:16
    Addison
    0

    Nested Content: NullReferenceException

    NullReferenceException caused when attempting to use nested content. This pattern is showing up in many places on my application. How is it possible to pass HasValue check but still throw NullReferenceException on attempt to access?

    Thanks!

    Error

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Dec 19, 2019 @ 22:56
    Alex Skrypnyk
    0

    Hi Addison

    What Umbraco version are you using?

    Are you sure that data is presented in the property?

    Alex

  • Addison 5 posts 75 karma points
    Dec 19, 2019 @ 23:11
    Addison
    0

    Alex,

    Thanks for your help. Umbraco 8.0.1. I am sure that the content is in and published in the nested content field.

    Thanks, Addison

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Dec 20, 2019 @ 13:33
    Nik
    1

    Hey Addison,

    Can you show more of your view? It's possible the error is lying to you about which line the issue is actually on :-)

    Nik

  • Brett Spencer 88 posts 259 karma points
    Jan 13, 2020 @ 20:22
    Brett Spencer
    0

    I'm having this same exact issue. Has anyone found any reasons why this is happening.

    • I have double checked that my items are now Elements.
    • I have renamed the property.
    • I have deleted all temp cache and rebuilt.
    • I have checked my nested property to make sure all properties of the element are filled in.

         @{
              if (Model.HasValue("social"))
              {
                  var socialAccounts = Model.Value<IEnumerable<IPublishedElement>>("social");
                  <!-- Social -->
                  <div class="social">
                      @foreach (var item in socialAccounts)
                      {
                          var url = item.Value<String>("accountUrl");
                          var title = item.Value<String>("SocialAccount");
                          <a href='@url' title='@title'><i class='fa @item.Value("socialIcon")'></i></a>
                      }
                  </div>
              }
          }
      

      enter image description here enter image description here enter image description here

    Update (over 24 hours later): I deleted and rebuilt the nested datatype and the element and I STILL have a null reference.

  • Gabor Ferencz 36 posts 167 karma points
    Jun 09, 2020 @ 06:24
    Gabor Ferencz
    0

    Hi, Ever found the issue with this? I'm running into an issue where tthe nested content value is throwing a nullreference error whe I try and access it from the indexvaluestranforming event of examine index

    enter image description here

  • Guido Adam 21 posts 65 karma points
    Jun 22, 2020 @ 12:45
    Guido Adam
    0

    Hi Gabor, not searched for or found the solution, but there's is a workaround that helpes to bypass this error:

    try adding a second (dummy)element to your nested content type. At some point this was a remedy to this exact error.

    Using ModelsBuilder also seems to do the trick, but upgrading older projects to use it, is not always the most efficient solution.

Please Sign in or register to post replies

Write your reply to:

Draft