FxCop Warning on Newly Generated Windows Form: DoNotInitializeUnnecessarily
The Windows Forms Designer generates the following code for Windows Forms Application projects in C#.
I am working on an app and when I build I get the following warning:
"Projectname.Form1.components is never assigned to, and will always have its default value null"
I did a search on Google and came up with the below on the msdn website but I am confused as to what has caused the error in the first place?
Quote:
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.
|
I understand what the message is saying I just don't get what I have done to cause it as I have not come across it before if that makes sense?