Hi
I have a UserControl called MyUserControl that has the following
constructor and InitializeComponent (automatically generated by VS):
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
I then inherit from the control with MyInheritedUserControl and add a
text box to the control, again the constructor and InitializeComponent
is automatically generated by the VS:
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 32)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'MyInheritedControl
'
Me.Controls.Add(Me.TextBox1)
Me.Name = "MyInheritedControl"
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
MyInheritedUserControl:
"'MyInheritedControl..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:
MyInheritedControl..ctor()MyInheritedControl.
InitializeComponent()MyInheritedControl.set_TextBo x1(
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.