MustInherit and Design Mode

L

Lance

I get an exception when attempting to open a form in
design mode if the form inherits from a form that is
declared as MustInherit. For example, if I have:

Public MustInherit Class TestFormBase
Inherits Windows.Forms.Form
'...Normal Windows Form Designer generated code here
Public MustOverride Function GetValue() As Integer
End Class

Public Class TestForm
Inherits TestFormBase
'...Normal Windows Form Designer generated code here
Public Overrides Function GetValue() As Integer
Return 100
End Function
End Class

Then I get the following exception when I attempt to open
TestForm in design mode:

The designer must create an instance of
type 'TestFormBase' but it cannot because the type is
declared as abstract.

Curiously, I do not get an exception if I open
TestFormBase in the designer.

Is there any way to avoid this exception?

Thanks,
Lance
 
M

Mattias Sjögren

Lance,
Is there any way to avoid this exception?

I would do something like this

#If DEBUG Then
Public Class TestFormBase
#Else
Public MustInherit Class TestFormBase
#End If

#If DEBUG Then
Public Overridable Function GetValue() As Integer
Throw New NotImplementedException
End Function
#Else
Public MustOverride Function GetValue() As Integer
#End If



Mattias
 

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