System.ComponentModel.IContainer components not used?
I'm trying to clean some warnings in my C# project, and I've a couple of them saying:
Warning 1 The fi开发者_StackOverfloweld 'Namespace.Class.components' is assigned but its value is
never used E:\WorkspacePath\Sources\Project\WorkItems\Class.designer.cs
If i look into the code, I can find:
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
I've read that this is indeed used by the designer, but he doesn't seem to use it at all. I would have deleted this line straight away if it wasn't for the comment. Commenting the line didn't seem to change the behavior of the designer, i could still open my menu view without any problems.
So my question is, is it safe to delete this line when i've the warning at compilation time, or this warning is rather "normal"? What should I do with it? Am I forgetting to do something with this component?
Thank you for your help,
It's usually not a good idea to manually edit code in the designer file, as the designer could get confused and cause some unexpected behavior. It may no be used at the moment, but certain controls (like imagelist) take this IContainer as a dependency.
The reason you're getting the compiler warnings is probably because you are missing the standard generated Dispose method override, which would prevent the warning. Here it 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);
}
Related problem:
I had a bunch of compiler warnings like this:
Warning CS0649 Field 'CreateMethodForm.components' is never assigned to, and will always have its default value null
I had the good dispose code.
But I had:
private System.ComponentModel.IContainer components;
And I needed to change to:
private System.ComponentModel.IContainer components = null;
精彩评论