Exception trying to instansiate an inherited form

R

Ron L

I have created a form for my application. Once the form was working, I
copied that form to a new form that would contain all the common elements of
all forms in my application and made the existing form inherit from the
common one. Now when I try to run my application I get the following error
when I open the form:

An exception occurred while trying to create an instance of
WebWinFormTry1.frmNITSSForm. The exception was "Constructor on type
MyAppTest.frmParentForm not found.".

The relevant code for the 2 classes is included below. Can anyone tell me
what I am doing wrong here. As far as I can tell, I have the constructor
for both defined.

TIA
Ron L


frmParentForm.vb:

Option Strict On


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data.OleDb

Public Class frmParentForm
Inherits System.Windows.Forms.Form

Protected frmMain As myAppMain
Protected textIsDirty As Boolean

#Region " Windows Form Designer generated code "

'Public Sub New() ' Default constructor not implemented. Need to pass
the parent form in to work.
' MyBase.New()

' 'This call is required by the Windows Form Designer.
' InitializeComponent()

' 'Add any initialization after the InitializeComponent() call

'End Sub

Public Sub New(ByRef frmMainNew As myAppMain)
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
frmMain = frmMainNew
Call BindAndLoadControls()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
.... code removed for brevity
#End Region

.... other common functions here

End Class



frmChildForm.vb:
Option Strict On


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data.OleDb

Public Class frmUserAdmin
Inherits MyAppTest.frmParentForm

Private dsUserList As New DataSet
Private dsUserData As New DataSet
Private dsPermissions As New DataSet
Private permsList As DataTable

#Region " Windows Form Designer generated code "

'Public Sub New() 'Default constructor not implemented. Need to pass in
main form to work.
' MyBase.New()

' 'This call is required by the Windows Form Designer.
' InitializeComponent()

' 'Add any initialization after the InitializeComponent() call

'End Sub

Public Sub New(ByRef frmMainNew As NITSSMain)
MyBase.New(frmMainNew)

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
frmMain = frmMainNew
Call BindAndLoadControls()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
.... Code removed for brevity

#End Region

.... code removed for brevity
End Class
 
R

Ron L

Sijin
Thanks for the response. I had tried that before with no luck, but I
tried again. I get the same error with both constructors. Do you have any
other suggestions?

Ron L
 
R

Ron L

Sijin
I just realized <embarrased> that the "error" I was seeing was the #$$%^
task list. However, I do have a problem with the form in design view. When
I try to look at the child form frmChildForm [Design] in the IDE I get the
following error message:

An error occurred while loading the document. Fix the error, and then
try loading the document again. The error message follows:
Object reference not set to an instance of an object

Thanks and sorry for the red herring.

Ron L
 
S

Sijin Joseph

Does the error in Design View occur even after writing a default
constructor for the child form?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph


Ron said:
Sijin
I just realized <embarrased> that the "error" I was seeing was the #$$%^
task list. However, I do have a problem with the form in design view. When
I try to look at the child form frmChildForm [Design] in the IDE I get the
following error message:

An error occurred while loading the document. Fix the error, and then
try loading the document again. The error message follows:
Object reference not set to an instance of an object

Thanks and sorry for the red herring.

Ron L

Hi Ron,

Where is the code for the class WebWinFormTry1.frmNITSSForm the error is
being thrown for that class?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
R

Ron L

Yes.

Ron L

Sijin Joseph said:
Does the error in Design View occur even after writing a default
constructor for the child form?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph


Ron said:
Sijin
I just realized <embarrased> that the "error" I was seeing was the
#$$%^ task list. However, I do have a problem with the form in design
view. When I try to look at the child form frmChildForm [Design] in the
IDE I get the following error message:

An error occurred while loading the document. Fix the error, and
then try loading the document again. The error message follows:
Object reference not set to an instance of an object

Thanks and sorry for the red herring.

Ron L

Hi Ron,

Where is the code for the class WebWinFormTry1.frmNITSSForm the error is
being thrown for that class?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph


Ron L wrote:

Sijin
Thanks for the response. I had tried that before with no luck, but
I tried again. I get the same error with both constructors. Do you
have any other suggestions?

Ron L




You parent form needs to have a default constructor explicitly defined.
i.e a constructor that takes no parameter.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph


Ron L wrote:


I have created a form for my application. Once the form was working,
I copied that form to a new form that would contain all the common
elements of all forms in my application and made the existing form
inherit from the common one. Now when I try to run my application I
get the following error when I open the form:

An exception occurred while trying to create an instance of
WebWinFormTry1.frmNITSSForm. The exception was "Constructor on type
MyAppTest.frmParentForm not found.".

The relevant code for the 2 classes is included below. Can anyone
tell me what I am doing wrong here. As far as I can tell, I have the
constructor for both defined.

TIA
Ron L


frmParentForm.vb:

Option Strict On


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data.OleDb

Public Class frmParentForm
Inherits System.Windows.Forms.Form

Protected frmMain As myAppMain
Protected textIsDirty As Boolean

#Region " Windows Form Designer generated code "

'Public Sub New() ' Default constructor not implemented. Need to
pass the parent form in to work.
' MyBase.New()

' 'This call is required by the Windows Form Designer.
' InitializeComponent()

' 'Add any initialization after the InitializeComponent() call

'End Sub

Public Sub New(ByRef frmMainNew As myAppMain)
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
frmMain = frmMainNew
Call BindAndLoadControls()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
... code removed for brevity
#End Region

... other common functions here

End Class



frmChildForm.vb:
Option Strict On


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data.OleDb

Public Class frmUserAdmin
Inherits MyAppTest.frmParentForm

Private dsUserList As New DataSet
Private dsUserData As New DataSet
Private dsPermissions As New DataSet
Private permsList As DataTable

#Region " Windows Form Designer generated code "

'Public Sub New() 'Default constructor not implemented. Need to
pass in main form to work.
' MyBase.New()

' 'This call is required by the Windows Form Designer.
' InitializeComponent()

' 'Add any initialization after the InitializeComponent() call

'End Sub

Public Sub New(ByRef frmMainNew As NITSSMain)
MyBase.New(frmMainNew)

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
frmMain = frmMainNew
Call BindAndLoadControls()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
... Code removed for brevity

#End Region

... code removed for brevity
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top