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 5441 posts 20364 karma points MVP 3x 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 1175 posts 4863 karma points MVP 2x 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 84 posts 253 karma points
    1 week ago
    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.

Please Sign in or register to post replies

Write your reply to:

Draft