InvalidOperationException When adding a new element in the Editor

I’m not sure if this is related to Unity 5.0 RC2, but I am just creating an EditorWindow. (Nothing crazy in my opinion).

So the problem is in my editor, when I click the Add button I get this error:

Its probably that I am doing it wrong. But, When I look at the line number (DescriptionEditorWindow.cs:148) its this:

        EditorGUILayout.EndVertical();

What does error really mean? Looking at my code, I assumed something was null but I validate that before calling Linq ( .ToList()) Any Ideas?

I also tried to force repaint the window, but that didn’t work either :confused:

So a terrible fix, but its editor code, is wrapping the whole OnGUI() with a try catch. Not really the best solution, but a solution:

    private void OnGUI()
    {
        try
        {
            EditorGUILayout.BeginVertical();
            {
                EditorGUILayout.BeginHorizontal();
                {
                    DrawHeader();
                }
                EditorGUILayout.EndHorizontal();

                //Draw a line underneath the header
                GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });

                EditorGUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Reload Descriptions", GUILayout.ExpandWidth(false)))
                        LoadDescriptions();

                    GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandHeight(false), GUILayout.Width(1) });

                    if (GUILayout.Button("Add", GUILayout.ExpandWidth(false)))
                        AddDescription();

                    GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandHeight(false), GUILayout.Width(1) });

                    if (GUILayout.Button("Remove", GUILayout.ExpandWidth(false)))
                        RemoveDescription();

                    m_RemoveID = EditorGUILayout.IntField(m_RemoveID, GUILayout.MaxWidth(30));


                }
                EditorGUILayout.EndHorizontal();

                //Draw a line underneath the header
                GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });

                //draw the descriptions
                DrawEditor();
            }
            EditorGUILayout.EndVertical();
        }
        catch
        {

        }
    }