Stewart Nightingale
Stewart Nightingale

Reputation: 29

'System.StackOverflowException' occurred in WindowsBase.dll

I'm new to StackOverflow and programming in general, so sorry in advance if I am not explaining things correctly.

I am getting the error message:

An unhandled exception of type 'System.StackOverflowException' occurred in WindowsBase.dll

This occurs when the following code gets to window.Show()

   public MainWindow()
    {
        myApp.Common.AppInfo.Local = "en-GB";

        SoftwareMaintenance.Seed();

        myApp5Db.Init(typeof(myAppDb_SQL2008));
        myAppDb.Init();

        if (myAppDb.IsValid)
        {
            Node.LoadTree(Node.ROOT); //loading the first level only
        }

        InitializeComponent();
    }

protected override void OnStartup(StartupEventArgs e)
    {
        DefaultTraceListener traceListener = new DefaultTraceListener();

        PresentationTraceSources.Refresh();
        PresentationTraceSources.DataBindingSource.Listeners.Add(traceListener);
        PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Error;


        base.OnStartup(e);


        if (true)
        {
            MainWindow window = new MainWindow();
            window.Show();
        }

    }

Now I've done a lot of research across the net and everything points to a loop being stuck. In my case I don't think this is the case, as another developers machine can run the code fine.

This other computer is exactly the same (HP EliteBook 8670p) except it has more RAM. My one 8GB's, the other 16GB's [could this be the cause?]

Software-wise both running Windows 8.1 x64, Visual Studio 2013. The SQL Server's on each machine differ, my machine running SQL Server 2012 Developers Edition, the other SQL Server 2008 Standard.

// The Call Stack after window.Show()

[Managed to Native Transition]

// First 3 Call Stack's showed once 

WindowsBase.dll!MS.Win32.SafeNativeMethods.GetKeyboardLayout(int dwLayout)
PresentationCore.dll!System.Windows.Input.TextServicesManager.PostProcessInput(object sender, System.Windows.Input.ProcessInputEventArgs e)
PresentationCore.dll!System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(System.Windows.Input.ProcessInputEventHandler postProcessInput, System.Windows.Input.ProcessInputEventArgs processInputEventArgs)

// The next 9 lines are repeated over 20+ times

PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()
PresentationCore.dll!System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject newFocus, System.Windows.Input.IKeyboardInputProvider keyboardInputProvider, bool askOld, bool askNew, bool forceToNullIfFailed)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject focus, bool askOld, bool askNew, bool forceToNullIfFailed)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement element)
InfragisticsWPF4.Controls.Interactions.XamDialogWindow.v14.1.dll!Infragistics.Controls.Interactions.XamDialogWindow.DialogManager.XamDialogWindow_LostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args, bool reRaised)
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args)
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args)

Upvotes: 2

Views: 2530

Answers (2)

Jeremy Thompson
Jeremy Thompson

Reputation: 65702

// The next 9 lines are repeated over 20+ times

PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() PresentationCore.dll!System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject newFocus, System.Windows.Input.IKeyboardInputProvider keyboardInputProvider, bool askOld, bool askNew, bool forceToNullIfFailed) PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject focus, bool askOld, bool askNew, bool forceToNullIfFailed) PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement element) InfragisticsWPF4.Controls.Interactions.XamDialogWindow.v14.1.dll!Infragistics.Controls.Interactions.XamDialogWindow.DialogManager.XamDialogWindow_LostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e) PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args, bool reRaised) PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args)

If I were to guess I'd say you must have a Key Event that gets triggered on every node of the TreeView/Node, focus in on the code in the XamDialogWindow_LostKeyboardFocus event...

Upvotes: 0

phoog
phoog

Reputation: 43056

StackOverflowException results not when a loop is stuck, but when a method calls itself too many times. This is called recursion. It can also be caused by mutual recursion, in which two or more methods call each other in repeated succession.

This could be happening if the code fragment that uses the new operator to create a new MainWindow instance is called by one of the methods called in the MainWindow constructor, or by any method called in one of those methods. I would suspect one of these lines:

myApp5Db.Init(typeof(myAppDb_SQL2008));
myAppDb.Init();

But other lines could be the culprit.

If you post your application's Main method, it might offer some clues, as would the code of the methods called by the MainWindow constructor, and the full method in which your while (true) loop is defined.

Another idea: if you check the call stack in the debugger, at the point where the exception is thrown, you ought to find out pretty quickly where the recursion is taking place.

Upvotes: 2

Related Questions