Question

I have this code, it's meant to be a singleton form that pops up and stays up and then is appended to (basically I have muti-threads that can give queries to the user, and I don't want a stack of them I want one to pop up then "keep filling") I am just setting up a basic test case class to check the logic but I got this error I don't understand

error:

 Error  2   Inconsistent accessibility: field type 'System.Collections.Generic.List<ActionType>' is less accessible than field 'frmVerdict.thingsToDo'

code:

public partial class frmVerdict : Form
{
    public List<ActionType> thingsToDo = new List<ActionType>();
    private int elementCounter = 0;
    private static frmVerdict _instance;

    public frmVerdict()
    {
        InitializeComponent();
    }
    public static frmVerdict GetInstance()
    {
        if (_instance == null) _instance = new frmVerdict();
        return _instance;
    }
    public void addAction(ActionType action)
    {
        elementCounter++;
        TextBox txtbx = new TextBox(); //TextBox txtbx = (TextBox)Controls["txtbx0001"];
        txtbx.Text = action.name;
        txtbx.Name = "txtbx" + elementCounter.ToString().PadLeft(4, '0');
        txtbx.Location = new Point(10, 30 * elementCounter);
        txtbx.Height = 20;
        txtbx.Width = 50;
        pnlVerdict.Controls.Add(txtbx); //these textboxes will be replaced by buttons
        thingsToDo.Add(action);            
    }
}

here is how I call it (this isn't the problem but I want people to know why I am doing the singleton)

frmVerdict form = frmVerdict.GetInstance();
if (!form.Visible)
{
    form.Show();
}
else
{
    form.BringToFront();
}
form.addAction(action);
Was it helpful?

Solution

Your ActionType type is either declared as internal or has no accessibility modifier, in which case it's internal by default.

The solution is to explicitly make it public or to make any members of public types which expose ActionType internal.

Further Reading

OTHER TIPS

You need to make the class ActionType public because the class frmVerdict has at least one public method that has ActionType as a parameter

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top