简体   繁体   English

错误:mscorlib.dll中发生了'System.StackOverflowException'类型的未处理异常

[英]Error: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

Today I started working with classes. 今天,我开始上课。 I created some classes to get my MainWindow.xmal.cs a bit smaller. 我创建了一些类来使MainWindow.xmal.cs变小。 After creating the first classes and debugging, I get the following error message: 创建第一个类并进行调试后,我收到以下错误消息:

Eine nicht behandelte Ausnahme des Typs "System.StackOverflowException" ist in mscorlib.dll aufgetreten. mscorlib.dll中的“典型.System.StackOverflowException”错误。

Eine nicht behandelte Ausnahme des Typs "System.StackOverflowException" ist in APPLICATION.exe aufgetreten. 可以在APPLICATION.exe中获取“ Typ。“ System.StackOverflowException”文件。

class Sprachpaket_ENG_Template01
{
    MainWindow MW = new MainWindow();

    public void Template01()
    {
        MW.checkBox_1_Bcc.Content = "Bcc:";
        MW.checkBox_1_Cc.Content = "Cc:";
    }

--> This causes the error: MainWindow MW = new MainWindow(); ->这会导致错误: MainWindow MW = new MainWindow();

From your edits and comments, you have this: 从您的编辑和评论中,您可以得到:

class Sprachpaket_ENG_Template01
{
    // Create a new MainWindow whenever Sprachpaket_ENG_Template01 is created
    MainWindow MW = new MainWindow();
}

class MainWindow()
{
    public MainWindow()
    {
        // Create a new Sprachpaket_ENG_Template01 whenever MainWindow is created
        Sprachpaket_ENG_Template01 ENG_01 = new Sprachpaket_ENG_Template01();
    }
}

You have an infinite loop here, which is why you're getting a stack overflow. 您在这里有一个无限循环,这就是为什么您会得到堆栈溢出的原因。

You probably wanted to pass MainWindow as a parameter to the Sprachpaket_ENG_Template01 constructor: 您可能想将MainWindow作为参数传递给Sprachpaket_ENG_Template01构造函数:

class Sprachpaket_ENG_Template01
{
    MainWindow MW;

    public Sprachpaket_ENG_Template01(MainWindow mw)
    {
        MW = mw;
    }
}

class MainWindow()
{
    public MainWindow()
    {
        Sprachpaket_ENG_Template01 ENG_01 = new Sprachpaket_ENG_Template01(this);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mscorlib.dll中发生了未处理的“System.StackOverflowException”类型异常 - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll 发生mscorlib.dll错误时发生未处理的“System.StackOverflowException”类型异常? - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll error occurred? 调用递归函数期间,mscorlib.dll中发生了'System.StackOverflowException'类型的未处理异常 - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll during calling recursive function RedisClientManager,mscorlib.dll中发生未处理的“System.StackOverflowException”类型异常 - RedisClientManager, An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll C# - 实体框架 - mscorlib.dll中发生未处理的“System.StackOverflowException”类型异常 - C# - Entity Framework - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll 在启动我的MVC3应用程序时,在mscorlib.dll中出现“类型'System.StackOverflowException'的未处理异常”? - On starting my MVC3 application, getting “An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll”? WPF telerik TreeView控件中的mscorlib.dll发生类型为'System.StackOverflowException'的未处理异常 - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll in WPF telerik TreeView Control 局部视图:mscorlib.dll中发生了'System.StackOverflowException'类型的未处理异常 - Partial View: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll 对三个整数数组进行排序时,mscorlib.dll中发生了类型为'System.StackOverflowException'的未处理异常 - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll when sorting array of three integers mscorlib.dll asp.net-mvc中发生类型为'System.StackOverflowException'的未处理异常 - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll asp.net-mvc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM