Object reference error in admin area - Telerik

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
Hello

I had a compile time error for Telerik.Mvc dll about ambiguous reference match in admin area and I un-referenced the Telerik.Mvc dll and re-referenced it and the compile time error was resolved.

But now when I try to access the admin I get the following runtime error:

Object reference not set to an instance of an object.


Html.Telerik().Menu().Name("Admin")
.BindTo("admin", (item, siteMapNode) =>
{
    if (!String.IsNullOrWhiteSpace(item.ControllerName))
    {
        //apply admin area as described here - https://www.nopcommerce.com/boards/t/20478/broken-menus-in-admin-area-whilst-trying-to-make-a-plugin-admin-page.aspx
        item.RouteValues = new RouteValueDictionary()
            {
                { "area", "Admin" }
            };
    }

    var imageUrl = siteMapNode.Attributes["ImageUrl"];
    if (imageUrl != null && !string.IsNullOrEmpty(imageUrl.ToString()))
    {
        item.ImageUrl = imageUrl.ToString();
    }

    var resourceName = siteMapNode.Attributes["nopResource"];
    if (resourceName != null && !string.IsNullOrEmpty(resourceName.ToString()))
    {
        item.Text = T(resourceName.ToString()).ToHtmlString();
    }

    if (ViewBag.SelectedMenuItem == item.Text)
    {
        item.Selected = true;
    }

    if (hideAdminMenuItemsBasedOnPermissions)
    {
        var permissionNames = siteMapNode.Attributes["PermissionNames"];
        if (permissionNames != null && !string.IsNullOrEmpty(permissionNames.ToString()))
        {
            item.Visible = permissionNames.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                .Any(permissionName => permissionService.Authorize(permissionName.Trim()));
        }
    }
})
.Items(x =>
{
    if (adminMenuPlugins.Count() > 0)
    {
        if (!hideAdminMenuItemsBasedOnPermissions ||
            permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
        {
            x.Add().Text(T("Admin.Plugins").ToHtmlString()).Items(y =>
            {
                foreach (var adminMenuPlugin in adminMenuPlugins)
                {
                    adminMenuPlugin.BuildMenuItem(y.Add());
                }
            });
        }
    }
})
.OpenOnClick(false)

.Render();

Source File: d:\Skydrive\Projects\Technomobiles\Technomobiles_source\Presentation\Nop.Web\Administration\Views\Shared\Menu.cshtml    


Full stacktrace: https://gist.github.com/mumair85/204903ffd326c631a3a5

So I tried to put this in try catch and admin area works fine, but the menu is not generated due to the above error. Can anyone help, or did anyone had this issue before?

Any idea how to resolve this issue?
10 years ago
Have you recently updated the Telerik component?
10 years ago
I didnt update it, first it was showing me error about the ambiguous match, so I re-referenced it.
And after that the error came.

So I tried a long shot: I unzipped a new nop source project (v2.80) and merged my necessary changes without touching the dlls and ran that, same problem...
10 years ago
It sounds like the version being referenced in the solution might not be the version deployed to the presentation. Can you confirm when you re-referenced the Telerik utility that it is also the version being loaded at runtime?

There is also this post in the Telerik forum regarding a misspelled controller causing a Null Ref in the menu items.

http://www.telerik.com/community/forums/aspnet-mvc/menu/null-reference-exception.aspx
10 years ago
I confirmed about the version, its the same version on live site folder, my dev folder and also extracted fresh nop2.80 and it has same version...

I will check for the controller name, but I dont think I have touched any of that part.
10 years ago
Someone else also had this issue earlier, but the fix would already be in here for 2.80?
https://www.nopcommerce.com/boards/t/17860/suddenly-started-getting-object-reference-null-exception-in-admin-menucshtml.aspx

Any suggestions?
10 years ago
If anyone still having this issue with older versions of NopCom do this to resolve it:

In
Admin > Views > Shared > Menu.cshtml


find and change the following:

Html.Telerik().Menu().Name("Admin")


To:

Html.Telerik().Menu().Name("Admin").SecurityTrimming(false)


So adding
SecurityTrimming(false)
resolves this issue.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.