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

[Solved] Binding to IEnumerable<MenuItem> gets Object reference not set to an instance...

0 Answers 51 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.
Jim
Top achievements
Rank 1
Jim asked on 08 May 2012, 09:26 PM
Think I found a bug in Menus from version 2012.1.214.340. I get error "Object reference not set to an instance of an object" when using method prototype #2 of the 5 listed at http://www.telerik.com/help/aspnet-mvc/overload_telerik_web_mvc_ui_menubuilder_bindto.html. The prototype is public MenuBuilder BindTo(IEnumerable<MenuItem> items).

I am passing a properly formed IEnumerable<MenuItem> with 5 menu items. Platform is Windows Server 2008R2 64-bit, MVC 3, VS2010.

The failing code is in MenuBuilder.cs line 239: 
    (items as List<MenuItem>).ForEach(item => Component.Items.Add(item));

I believe the List<MenuItem> part is failing to convert the IEnumerable. It works perfectly if I rewrite this as
    var foo = new List<MenuItem>(items);

    foo.ForEach(item => Component.Items.Add(item));

Tags
Menu
Asked by
Jim
Top achievements
Rank 1
Share this question
or