System.ComponentModel.IContainer components not used?

I am trying to clear some warnings in my C # project, and I have a couple of them:

Warning 1 The field 'Namespace.Class.components' is assigned but its value is never used E:\WorkspacePath\Sources\Project\WorkItems\Class.designer.cs 

If I look at the code, I can find:

 /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; 

I read that this is really used by the designer, but he doesn't seem to use it at all. I would immediately delete this line, if not for the comment. Commenting that the line didn't seem to change the designer’s behavior, I could still open the menu without any problems.

So my question is: is it safe to delete this line when I have a warning at compile time, or is this warning pretty "normal"? What should I do with this? Am I forgetting to do something with this component?

Thank you for your help.

+4
source share
2 answers

It is usually not recommended to manually edit the code in the constructor file, as the designer may get confused and cause some unexpected behavior. It cannot be used at the moment, but some controls (for example, imagelist) perceive this IContainer as a dependency.

The reason you get warnings about the compiler is probably due to the fact that you are missing the standard method of overriding the Dispose method, which will prevent the warning. Here he is:

  /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } 
+4
source

Related problem:

I had a few compiler warnings like this:

Warning CS0649 The 'CreateMethodForm.components' field is never assigned and will always be null by default.

I had a good recycling code.

But I had:

 private System.ComponentModel.IContainer components; 

And I needed to change to:

 private System.ComponentModel.IContainer components = null; 
0
source

All Articles