' System.StackOverflowException'发生在WindowsBase.dll

时间:2015-06-15 23:46:17

标签: c# wpf

我是StackOverflow和一般编程的新手,如果我没有正确解释,请提前抱歉。

我收到错误消息:

  

未处理的类型' System.StackOverflowException'发生在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)

2 个答案:

答案 0 :(得分:2)

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

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

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

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

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

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

答案 1 :(得分:0)

  

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

     

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   焦点,bool askOld,bool askNew,bool forceToNullIfFailed)   PresentationCore.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)   PresentationCore.dll中!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate   处理程序,对象目标)   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   参数)

如果我猜测我说你必须在TreeView / Node的每个节点上触发一个关键事件,请关注{{1}中的代码event ...