This is a migrated thread and some comments may be shown as answers.

[Solved] Null Reference Exception

3 Answers 145 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Scott Rose
Top achievements
Rank 1
Scott Rose asked on 08 Oct 2010, 11:09 PM
I have a menu where the items are built dynamically from the database.  I have a collection of menu objects which in turn contain collections of child menu items.   I had been using my setup for a few months with no problems until lately when a new menu item with submenus was added to the database.  As soon as this new item was added a null reference exception started happening on the menu control.  I've examined the objects which are all populated and look fine.  Any ideas on what might be causing this?  

   at Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizeAttributeCache.GetAuthorizeAttributes(RequestContext requestContext, String controllerName, String actionName)
   at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerAuthorization.IsAccessibleToUser(RequestContext requestContext, String controllerName, String actionName)
   at Telerik.Web.Mvc.Infrastructure.Implementation.NavigationItemAuthorization.IsAccessibleToUser(RequestContext requestContext, INavigatable navigationItem)
   at Telerik.Web.Mvc.UI.NavigatableExtensions.<>c__DisplayClass2`1.<IsAccessible>b__1(T item)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Telerik.Web.Mvc.UI.NavigatableExtensions.IsAccessible[T](IEnumerable`1 items, INavigationItemAuthorization authorization, ViewContext viewContext)
   at Telerik.Web.Mvc.UI.NavigationItemContainerExtensions.WriteItem[TComponent,TItem](TItem item, TComponent component, IHtmlNode parentTag, INavigationComponentHtmlBuilder`1 builder)
   at Telerik.Web.Mvc.UI.Menu.<>c__DisplayClass4.<WriteHtml>b__3(MenuItem item)
   at Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each[T](IEnumerable`1 instance, Action`1 action)
   at Telerik.Web.Mvc.UI.Menu.WriteHtml(HtmlTextWriter writer)
   at Telerik.Web.Mvc.UI.ViewComponentBase.ToHtmlString()
   at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString()
   at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToString()
   at System.Web.HttpWriter.Write(Object obj)
   at System.Web.Mvc.ViewPage.SwitchWriter.Write(Object value)
   at System.Web.UI.HtmlTextWriter.Write(Object value)
   at ASP.views_shared_maintelerikmenu_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Raptor\Dev\src\WebApps\HN\Views\Shared\MainTelerikMenu.ascx:line 4
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.Control.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.Page.Render(HtmlTextWriter writer)
   at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Here is my menu in the view:

<%= Html.Telerik().Menu()
        .Name("Menu")
    .BindTo(Model, mappings =>
     {
        mappings.For<HN.Configuration.Menu>(binding => binding
        .ItemDataBound((item, parentMenu) =>
        {
               item.Text = parentMenu.Name;
           if (string.IsNullOrEmpty(parentMenu.ControllerName) == false)
           {
              item.ActionName = parentMenu.ActionName;
              item.ControllerName = parentMenu.ControllerName;
              item.RouteValues.Add("SessionToken", ViewData["SessionToken"]);
        }                            
            })
        .Children(parentMenu => parentMenu.items));
    mappings.For<HN.Configuration.MenuItem>(binding => binding
            .ItemDataBound((item, childMenu) =>
            {
            item.Text = childMenu.Name;
            item.ActionName = childMenu.ActionName;
            item.ControllerName = childMenu.ControlName;
                item.RouteValues.Add("SessionToken", ViewData["SessionToken"]);
            }));
        })
%>

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 11 Oct 2010, 08:09 AM
Hi Scott Rose,

 Is it possible to send us a sample project? We have not been able to reproduce the NullReferenceException in a test project so far.

All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Scott Rose
Top achievements
Rank 1
answered on 12 Oct 2010, 04:27 PM
I found the issue.  There was a typo in the controller name of one of the new submenus.  I guess the menu control is trying to validate the controller before rendering the menu.  Once the typo was fixed the menu rendered correctly.  It kind of concerns me that one bad link could kill off the page.
0
Georgi Krustev
Telerik team
answered on 13 Oct 2010, 09:07 AM
Hello Scott,

Thank you for your feedback.

I glad to inform you that we decide to change the aforementioned behavior and now if there is no such controller authorization will not throw exception. Menu will render URL pointing to the in-existing controller.

The change will be included in the next official release of Telerik Components for ASP.NET MVC.

Kind regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Menu
Asked by
Scott Rose
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Scott Rose
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or