Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 13th, 2010, 03:53 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default is never assigned to, and will always have its default value null

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?
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old March 2nd, 2010, 10:37 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

Never worry about any FxCop (or Resharper etc) warning about any VS generated code (GUI stub, Web Service stub, entity framework stub etc.).

Last edited by PeterPeiGuo; March 2nd, 2010 at 10:42 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box assigned to a field not working rmccafferty Access 1 September 14th, 2009 04:19 PM
Null inserted by form even when field has default Kia VB Databases Basics 1 July 24th, 2007 01:47 PM
Notice: Only variables should be assigned by refer harpua Beginning PHP 0 August 22nd, 2006 10:47 AM
variable used before it has been assigned a value BenCh BOOK: ASP.NET Website Programming Problem-Design-Solution 1 February 10th, 2006 02:03 PM
how to find assigned images of controls? saravananedu VB How-To 9 July 29th, 2005 01:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.