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

前端 未结 16 989
甜味超标
甜味超标 2020-12-15 03:14

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

16条回答
  •  盖世英雄少女心
    2020-12-15 03:50

    In my case, I had an older Windows Forms project where InitializeComponents() started like this:

    private void InitializeComponent()
    {
        var componentResourceManager = new ComponentResourceManager(typeof(MyForm));
        ...
    

    This resulted in an error message later on when accessing the componentResourceManager inside InitializeComponent():

    The variable 'componentResourceManager' is either undeclared or was never assigned.

    When comparing with a newly created form, I saw that it was similar to my non-working form, except for one thing:

    The variable was not named componentResourceManager but simply resources.

    Solution

    After doing a rename on my variable to also have the name resources, everything works successfully:

    private void InitializeComponent()
    {
        var resources = new ComponentResourceManager(typeof(MyForm));
        ...
    

    The Windows Forms Designer in Visual Studio 2017 did open the form correctly.

提交回复
热议问题