Unhandled exception in Windows Form Designer generated code
I have 2 projects within the same solution. I can build both projects and build the solution without a problem. When I go to debug I get a:
An unhandled exception of type 'System.StackOverflowException' occurred in GradeReport.exe
The error takes me to the MyBase.New() line in my code. Can anyone tell me what this means or how to fix it?? Thanks
VB Code:
#Region " Windows Form Designer generated code "
Public Sub New()
------> MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Re: Unhandled exception in Windows Form Designer generated code
This just inherits from System.Windows.Forms.Form? If so, what variables do you have declared in the form?
Re: Unhandled exception in Windows Form Designer generated code
Just some basic stuff to load combo boxes. I have the code in classes.
VB Code:
Dim myLS As New clsLoadCombo
Dim myLV As New clsLoadListView
Dim myBQ As New clsBuildSQL
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lvwSelectedFields.Clear()
myLS.loadSortBy(cboSortBy)
myLS.loadSelectField(cboSelectField)
myLS.loadSelectView(cboSelectByValue, cboBuilding.Text)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lvwSelectedFields.Clear()
myLS.loadSortBy(cboSortBy)
myLS.loadSelectField(cboSelectField)
myLS.loadSelectView(cboSelectByValue, cboBuilding.Text)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim myPR As New clsPrint
Dim report As String
Dim query As String
'Send report name and query to print function.
query = myBQ.BuildSql
myPR.PrintReport(report, query)
End Sub
Re: Unhandled exception in Windows Form Designer generated code
put a break at the call to InitializeComponent() in Sub New()...follow that by using F11. You have a loop in that sub that is causing that.
Re: Unhandled exception in Windows Form Designer generated code
It didn't make it to the InitializeComponent(), so I put a break at the myBase.New(). It goes back and forth between the myBase.New() and my first class declaration, so I see what you are saying about the loop.
---> Dim myLV As New clsLoadListView
Dim myBQ As New clsBuildSQL
Dim myPR As New clsPrint
Dim myLS As New clsLoadCombo
Re: Unhandled exception in Windows Form Designer generated code
I took out the class declarations and placed them inside each sub they are used in. Everything works fine now. But my question is, hwo can I only declare a class once and use it throughout the scope of the form in different subs?
Re: Unhandled exception in Windows Form Designer generated code
Try declaring your variables at the class level but not instantiating them until the constructor or Load event handler. I think this should fix the symptoms but I'm not sure what the underlying cause would be. Perhaps there is an issue with your clsLoadListView class.
Re: Unhandled exception in Windows Form Designer generated code
I had the same feeling about the clsLoadListView class. So I commented that line out. And the same thing happens with the rest of my classes as well.
But I will try your suggestion and get back with you.