c# - WindowsBase.dll 中发生“System.StackOverflowException”

标签 c# wpf

我对 StackOverflow 和一般编程都很陌生,如果我没有正确解释,请提前抱歉。

我收到错误消息:

An unhandled exception of type 'System.StackOverflowException' occurred in WindowsBase.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 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)

最佳答案

StackOverflowException 的结果不是循环被卡住,而是方法调用自身次数过多。这称为递归。它还可能是由相互递归引起的,其中两个或多个方法连续重复调用对方。

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

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

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

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

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

关于c# - WindowsBase.dll 中发生“System.StackOverflowException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30856742/

相关文章:

c# - 在 MVVM 中使用 CommandParameter 传递类变量

c# - 通用类型约束如何工作?

c# - 是否有任何库/框架用于撤消/重做数据库中行的更改?

c# - 根据行/列值设置 GridView 值 ItemStyle ForeColor

c# - 如何检测 WatiN 中的 Javascript 弹出通知?

wpf - ObservableCollection 和 INotifyPropertyChanged 有什么区别?

wpf - mvvm 更新计算字段

c# - .Net 中的定时器和循环是否准确?

c# - 更新项目时,Datagrid 不维护排序

wpf - 命令模式和参数设计