“System.StackOverflowException”发生在WindowsBase.dll中

本文关键字:WindowsBase dll System StackOverflowException | 更新日期: 2023-09-27 17:56:38

我是StackOverflow和编程的新手,所以如果我没有正确解释事情,请提前道歉。

我收到错误消息:

WindowsBase 中发生了类型为"System.StackOverflowException"的未处理异常.dll

当以下代码到达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();
        }
    }

现在我已经在网上做了很多研究,一切都表明一个循环被卡住了。就我而言,我认为情况并非如此,因为另一台开发人员机器可以很好地运行代码。

另一台计算机完全相同(HP EliteBook 8670p),只是它有更多的RAM。我的一个8GB,另一个16GB的[这可能是原因吗?

软件方面都运行Windows 8.1 x64,Visual Studio 2013。每台机器上的SQL Server都不同,我的机器运行SQL Server 2012 Developers Edition,其他SQL Server 2008标准版。

// 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)

“System.StackOverflowException”发生在WindowsBase.dll中

StackOverflowException 不是在循环卡住时的结果,而是当方法调用自身太多次时。 这称为递归。 它也可能是由相互递归引起的,其中两个或多个方法重复连续地相互调用。

如果使用 new 运算符创建新的 MainWindow 实例的代码片段由 MainWindow 构造函数中调用的方法之一调用,或者由其中一个方法中调用的任何方法调用,则可能会发生这种情况。 我怀疑其中一行:

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

但其他线路可能是罪魁祸首。

如果发布应用程序的 Main 方法,它可能会提供一些线索,MainWindow 构造函数调用的方法的代码以及定义while (true)循环的完整方法也是如此。

另一个想法:如果你在调试器中检查调用堆栈,在抛出异常的地方,你应该很快找出递归发生的位置。

接下来的 9 行重复超过 20+ 次

演示核心.dll!System.Windows.Input.InputManager.ProcessStagingArea() 演示核心.dll!System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject newFocus, System.Windows.Input.IKeyboardInputProvider keyboardInputProvider, bool askOld, bool askNew, bool forceToNullIfFailed) 演示核心.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject focus, bool askOld, bool askNew, bool forceToNullIfFailed) 演示核心.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement 元素) InfragisticsWPF4.Controls.Interactions.XamDialogWindow.v14.1.dll!Infragistics.Controls.Interactions.XamDialogWindow.DialogManager.XamDialogWindow_LostKeyboardFocus(对象 sender, System.Windows.Input.KeyboardFocusChangedEventArgs e) 演示核心.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate 处理程序,对象目标) 演示核心.dll!System.Windows.EventRoute.InvokeHandlersImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args, bool reraised) 演示核心.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) 演示核心.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs 参数)

如果我猜到,我会说你必须有一个在 TreeView/Node 的每个节点上触发的密钥事件,请专注于 XamDialogWindow_LostKeyboardFocus 事件中的代码......