The variable 'variable_name' is either undeclared or was never assigned

Kitinz picture Kitinz · Dec 15, 2011 · Viewed 39.7k times · Source

I have a question related to the error on the title. Im working with c# and Visual Studio 2010.

I have a form declared as "public class FormularioGeneral : Form", which is the base for the rest of the forms in my application. When i try to access the Designer View i get this error several times, as you can see in the image:

Sample of errors All the errors references lines inside the InitializeComponent method, where the value is assigned to a property like this one:

[...]            
this.PanelMargenIzquierdoCapaBase.BackColor = m_ColorCapaBase;
[...]

But all the variables are declared in the same class as read-only properties and all of them are assigned inside a method which is called in the constructor.

Declaration of properties:

    protected Color m_VariableName;
    public Color VariableName
    {
        get { return m_VariableName; }
        set { }
    }

Constructor code:

    public FormularioGeneral()
    {
        ConfigurarUI();
        AccionesConstructor();
        InitializeComponent();
        PostInicializacionComponentes();
        EstablecerIcono();
        InicializarLocalizacionFormulario();
    }

ConfigurarUI method:

public virtual void ConfigurarUI()
{
        [...]

        m_AltoBordeSuperiorCapaBase = 30;
        m_AltoBordeInferiorCapaBase = 7;
        m_AnchoBordesLateralesCapaBase = 7;

        m_ColorCapaBase = Color.FromArgb(50, 100, 150);
        m_ColorTextoCapaBase = Color.White;
        m_ColorTextoBotonAplicacion = Color.Black;

        m_FuenteTextoIzquierdoCapaBase = new System.Drawing.Font("Verdana", 11.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        m_FuenteTextoCentroCapaBase = new System.Drawing.Font("Verdana", 14.0F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        [...]
}

So, as far as i know, all the variable which are giving the errors are correctly declared and have a value assigned before the InitilizeComponent function is called.

Im stuck at this point and dont know what to do to solve the problem. Hope some of you can help me with this issue.

Answer

Lucas picture Lucas · Jul 2, 2013

So, I have had the same problem in the past, for fix I did the following:

  • Solution → Clean Solution;
  • Build → Rebuild Solution;
  • Close Visual Studio, re-open.

Thanks a lot to Marshall Belew!