Hi
I have a UserControl called MyUserControl that has the following
constructor and InitializeCompo nent (automatically generated by VS):
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
Private Sub InitializeCompo nent()
components = New System.Componen tModel.Containe r()
End Sub
I then inherit from the control with MyInheritedUser Control and add a
text box to the control, again the constructor and InitializeCompo nent
is automatically generated by the VS:
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
Private Sub InitializeCompo nent()
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(16, 32)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'MyInheritedCon trol
'
Me.Controls.Add (Me.TextBox1)
Me.Name = "MyInheritedCon trol"
Me.ResumeLayout (False)
End Sub
My company is implementing FxCop
(http://www.gotdotnet.com/team/fxcop/), a fantastic utility, but it
flags the following warning on the constructor in
MyInheritedUser Control:
"'MyInheritedCo ntrol..ctor()' contains a call chain that results in a
call to a virtual method defined by the class. Review the following
call stack for unintended consequences:
MyInheritedCont rol..ctor()MyIn heritedControl.
InitializeCompo nent()MyInherit edControl.set_T extBox1(
TextBox WithEventsValue )"
"Virtual methods defined on the class should not be called from
constructors. If a derived class has overridden the method, the
derived class version will be called (before the derived class
constructor is called)."
With a link to more information:
http://www.gotdotnet.com/team/fxcop/...orVirtual.html
Can someone explain what is actually wrong here please?
Thanks
Blu.