Copied to clipboard

Flag this post as spam?

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


  • Jon 38 posts 157 karma points
    Feb 09, 2015 @ 18:21
    Jon
    0

    Cannot perform runtime binding on a null reference

    I have a Macro that I've used on several sites. I built it in my core site that I base all other sites on. I just returned to that site to do some other development and noticed the main menu is not working.

    I get this error:

    Cannot perform runtime binding on a null reference 
    at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_Views_MacroPartials__Navigation_cshtml.Execute() in [snip]\MacroPartials\_Navigation.cshtml:line 39

    Here is the code:

    @if (nav != null)
    {
    <nav class="@nav.GetPropertyValue("Navigation CSS Class ")">
    <ul>
    @foreach (IPublishedContent item in nav.Children())
    {
    if (item.HasValue("Link"))
    {
    try
    {
    IPublishedContent link = item.GetPropertyValue<IPublishedContent>("Link");

    <li class="@((page.Id == link.Id) ? "selected" : "") @item.GetPropertyValue("Link CSS Class")"><a href="@link.Url">@item.GetPropertyValue("Text")</a></li>
    }
    catch (Exception ex)
    {
    <li>@ex.Message <pre>@ex.StackTrace</pre></li>
    }
    }
    }
    </ul>
    </nav>
    }

    This is the line that fails:

    IPublishedContent link = item.GetPropertyValue<IPublishedContent>("Link");

    This is currently working fine on five other websites and was working on this one until I returned to it today.

    I have no idea what's causing the error, can anyone help?

    Jon

  • Barry Matthewson 6 posts 26 karma points
    Feb 09, 2015 @ 19:33
    Barry Matthewson
    0

    Hi Jon -

    I'm not sure if this is the case here, but I've seen cases like this where the line being reported in not actually the one causing the error. Can you check that your "link" object is not null? It doesn't seem likely that the "item" object would be.

    Thanks.

    Barry

     

Please Sign in or register to post replies

Write your reply to:

Draft