tags:

views:

538

answers:

1

Dear all, I'm trying to clean some warnings in my C# project, and I've a couple of them saying:

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 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,

A: 

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);
    }
jancow
This successfully takes out the warning, but am i supposed to override it? Im not implementing IDisposable, so this Dispose method should be inherited from a basic class right (thus the override statement in the proposed solution).I will correct the classes with this solution, but i still dont get why we are supposed to do this manually or why the generated code creates warnings.
Srodriguez
What kind of component is this? Whatever your component is inheriting from (e.g. Form, UserControl etc.) does implement IDisposable. Creating a new component from scratch should surely generate this code. Can you confirm this?
jancow