tags:

views:

1183

answers:

3

I have three classes MainMenu, SubMenu and Secondary SubMenu. I have a cascading drop down box which is used when creating Secondary Submenu. A main menu is selected which then shows a drop down with sub menus. When I select an item in the MainMenu drop-down box I get an error:

System.InvalidOperationException: A circular reference was detected while serializing an object of type 'System.Reflection.Module'.

The SubMenu references the MainMenu and the SecondaryMenu references the SubMenu.

I'm not sure where to begin looking for the error?

+2  A: 

Well, what is SubMenu?

This typically happens with tree serializers (such as XmlSerializer and JSON implementations, etc) if you have a "parent" relationship. Does your sub-menu know about its parent? Can you make this an internal property, perhaps? Or mark it to be ignored?

Marc Gravell
+1  A: 

The Json methods convert any object structure to Json using reflection/recursion if an object A references another object B that in turn references object A you got yourself an infinite loop. Does submenu have parent and children properties ? If so in most cases you only need the 1.

Martijn Laarman
Thanks. I've have three menus. A Main Menu, a Sub Menu and then a Secondary Sub Menu. The Sub Menu references the Main Menu and the Secondary Sub Menu references the Sub Menu, is this wrong?
Roslyn
Ok, so you pass the JSONResult an array of SubMenu's which link back to MainMenu. Is there any property on main menu that could possibly link back ? Perhaps you could update your question describing the three classes and their public properties ? That way others can have a look and answer as well :)
Martijn Laarman
I had added another property to the MainMenu which references a Css Style. When I remove the Css Style property the cascading menus works again.
Roslyn
+1  A: 

I was able to solve the error with the help of the following link

Roslyn