CS0649 ClassName.Components is never assigned to, and will always have its default value null

412 views
Skip to first unread message

mgmort mgmort

unread,
Apr 17, 2018, 7:27:18 AM4/17/18
to Migrated By Firefly
Whenever i make a change in a view that was migrated from magic, i get the build warning "CS0649 MethodName.Components is never assigned to, and will always have its default value null" for that view.

The warning points to the line  "System.ComponentModel.IContainer components;" which is usually the first line in the ClassName.Designer class.

Apparently what is happening is that in "void InitializeComponent()", as soon as I make a change in the gui, Studio is erasing the first line:
components = new System.ComponentModel.Container();
and this is the only place that "components" is used.

The warning can be suppressed either by manually replacing the "components = new System.ComponentModel.Container();" line,
or by removing the "System.ComponentModel.IContainer components;" line.

Easy enough to fix, but annoying to deal with every time I make a change in a view.

1. Is there any way to prevent the problem?

2. Is there any reason to keep this definition and assignment? they don't seem to serve any obvious function

Noam Honig

unread,
Apr 17, 2018, 7:41:54 AM4/17/18
to mgmort mgmort, Migrated By Firefly
Hi,

Short answer it has no affect and you can ignore it.

Long answer:

Microsoft's Windows Forms template includes a components member that it uses for it's stuff.

It also has the this.components = new SystemComponentModel.Container(); in the InitializeComponent method

And when you design the that form (not a migrated form) ironically it also removes that "components = new..." line from the method.

The only difference between a migrated for and the Visual Studio template is that by default the member is assigned with null:

Windows Forms Template:
private System.ComponentModel.IContainer components = null;

Migrated Form:
System.ComponentModel.IContainer components;

Since anyhow a member that wasn't assigned with a value, has null in it - we didn't write the = null.

So as you can see it's completely semantic.

If you still care and want that message to go away replace:
System.ComponentModel.IContainer components; 

with:
System.ComponentModel.IContainer components = null; 

You can even do it with search replace on all your code if you want - (save it first please :))

IF you still haven't done the final migration and want us to add the = null before you do - open a ticket for it and mention this post.

I hope this helps
Noam



--
You received this message because you are subscribed to the Google Groups "Migrated By Firefly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to migrated-by-fir...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages