
FxCop Warning on Newly Generated Windows Form: DoNotInitializeUnnecessarily
The Windows Forms Designer generates the following code for Windows Forms Application projects in C#.
private System.ComponentModel.IContainer components = null;
Depending on which FxCop rules are in effect, FxCop may produce the "DoNotInitializeUnnecessarily" warning. This is because null is the Common Language Runtime (CLR) default for reference properties.
If the designer did not initialize the components field to null, the C# compiler would produce the following warning:
"Form1.components is never assigned to, and will always have its default value null."
You can suppress the FxCop warning with SuppressMessageAttribute, but this can cause maintenance issues if the class name is changed. Therefore, it is recommended that you ignore the FxCop warning.