Cannot evaluate expression because the current thread is in a stack overflow state.(C#)

StackOverflow https://stackoverflow.com/questions/22602166

  •  19-06-2023
  •  | 
  •  

Pergunta

I am writing an application in C# which looks like this:

public partial class MainForm : Form
{

    WICForm Frm = new WICForm();

    public MainForm(){}

}

Where _MainForm_ and _WICForm_ are two different forms in the same application. But when I run the application I get the above error when creating a new instance Frm of WICForm. What could be the reason?

Foi útil?

Solução

Presumably, you are creating a new instance of MainForm in the constructor in WICForm (or from some code called from within it).

That way the MainForm and WICFormclasses are calling and constructing new instances of each other recursively, which will result in a stack overflow exception.

Tip: Put a breakpoint on the line containing new WICForm(); (place the cursor on that line and press F9). When you run the code in debug mode now, you can step into that method to see what it does.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top