Question

The following is the stack trace error I get when I try to run my site through a validator like http://validator.w3.org/ or the facebook open graph debugger. The thing is, the page appears to load just fine in the browser, or in the mobile app web view. The only way I can see this error is by having the validator show me error pages (option). Any suggestions about how to read the stack trace? I see the reference to one of my controllers Literrater.Controllers.BookController.Index(Int32 id, String slug) but I havent changed anything and it used to work, and it works fine in the browser. So, I'm confused. Do I need to check redirect happening or something?

The follow page has the problem. http://literrater.azurewebsites.net/book/33625/birdsong-a-novel-of-love-and-war

 [RuntimeBinderException: Cannot convert null to 'bool' because it is a non-nullable value type]
  CallSite.Target(Closure , CallSite , Object ) +115
 System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +661
 Literrater.Controllers.BookController.Index(Int32 id, String slug) +13725
 lambda_method(Closure , ControllerBase , Object[] ) +146
 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +182
 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27

    System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
  System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
    System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +58
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +225
     System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +225
Was it helpful?

Solution

At this moment, your page is not loading and producing the error:

Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot convert null to 'bool' because it is a non-nullable value type

Source Error: 


Line 32:         <div class="status-wrapper">
Line 33:             <h2 class="sub-title">Collections</h2>
Line 34:             @{Model.CollectionVM.FacebookStatus = ViewBag.FacebookStatus;}
Line 35:             @Html.Partial("_MiniBookStatus", Model.CollectionVM)
Line 36:             

Source File: d:\home\site\wwwroot\Views\Book\Index.cshtml    Line: 34 

It looks like maybe you did not initialize the ViewBag.FacebookStatus value in your controller. With those ViewBag values, if you don't set the value in all code paths, then you may have a case like this where the it's null.

As an example:

protected ActionResult Test()
{
    ViewBag.SomeString = string.Empty;
    ViewBag.SomeBool = false;

    //some code
    if (condition)
    {
        ViewBag.SomeBool = true;
    }
    else
    {
        ViewBag.SomeString = "Yea I'm a string!";
    }

    return View();
}

It's good practice to init the ViewBag values or it can come back to bite you in the Razor view because Intellisense won't pick it up, and it won't cause a build error or warning.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top