EditorApplication.NewScene Error.

Hi, I’m Having some issues with Unity,I’m doing a Unity Editor Extension to have easy access to some Unity functions like create a scene, save a scene or open scene. I’m trying to create a New Scene With Code, with EditorApplication.NewScene(); but the console is showing me this error.

InvalidOperationException: Operation is not valid due to the current state of the object
System.Collections.Stack.Peek () (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections/Stack.cs:321)
UnityEngine.GUILayoutUtility.EndLayoutGroup () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:222)
UnityEngine.GUILayout.EndHorizontal () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayout.cs:243)
SettingsBar.OnGUI () (at Assets/Editor/ByDesign Games Tools/SettingsBar.cs:113)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

Here is My code

settingsBarcontent.tooltip = "New Scene";
settingsBarcontent.image=Resources.Load("New")as Texture2D;
		if ( GUILayout.Button( settingsBarcontent, SettingsBar, GUILayout.MaxWidth(24) ) ) {
			EditorApplication.NewScene();
		}

What I’m Doing Wrong? any suggestion?

Here is the full code:
[25791-settings.txt|25791]

Try the following code in your button:

if(!EditorApplication.isUpdating) EditorApplication.NewScene();

Also,
On another answer, it mentioned it could be due to Unitys GUI layout.

Try resetting your layout to Default.