这里是程序的主要部分,似乎与异常有关。
using System.Drawing;
using Framework.pages;
namespace Framework
{
public partial class MainWindow : Window
{
public string status;
public MainWindow()
{
InitializeComponent(); // Unhandled exception here
InitializeTheme();
activationStep page = new activationStep();
page.loadPage();
}
// etc etc
这是抽象类
namespace Framework.pages
{
abstract class template : MainWindow
{
public abstract void loadPage();
public abstract void loadTheme();
}
}
这是激活步骤类
using System.Windows.Media;
namespace Framework.pages
{
class activationStep : template
{
public override void loadPage()
{
//this.loadTheme();
}
public override void loadTheme()
{
// Default green activation button
//activateButton.Background = (SolidColorBrush)new BrushConverter().ConvertFromString(Framework.theme.darkGreen);
//activateButton.BorderBrush = (SolidColorBrush)new BrushConverter().ConvertFromString(Framework.theme.borderGreen);
// Set form error color to red
//activationFormError.Foreground = System.Windows.Media.Brushes.Red;
}
// etc etc
问题是如果我从 MainWindow 类中注释掉这两行:
activationStep page = new activationStep();
page.loadPage();
尽管实际上 activationStep 类中的所有内容都被注释掉了(即使它们也没有被注释掉),程序仍然运行良好?我完全不知道为什么我会收到这个特殊的异常,因为似乎肯定没有任何强烈的循环或任何东西。
-值得注意的是,表单中加载的组件确实不多,而且通常运行流畅。
最佳答案
您正在“新建”一个 activationStep
,它派生自 template
,而 template
又派生自 MainWindow
,其构造函数创建一个新的 activationStep
...等等
这个循环运行了一段时间,然后你得到了一个StackOverflowException
。
您需要重新考虑您的设计。
关于C# 'System.StackOverflowException' 在 InitializeComponent(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20888373/