Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Inconsistent accessibility error

Tags:

c#

I got a little bit of a problem and I cant seem to solve it can someone help me,
These are the errors:

Error 1 Inconsistent accessibility: field type 'Flashloader.Toepassing' is less accessible than field 'Flashloader.NewApplication.Toepassing'

Error 2 Inconsistent accessibility: parameter type 'Flashloader.toepassinginifile' is less accessible than method 'Flashloader.NewApplication.NewApplication(Flashloader.toepassinginifile)'

So those where the errors but a source is very useful in this case.

Source 1 New application(This is a Winform):

namespace Flashloader{

public partial class NewApplication : Form
{
    private toepassinginifile _toepassinginifile;

    //private controllerinifile _controlIniFile;

    public Toepassing toepassing = new Toepassing();

    public NewApplication(toepassinginifile iniFile)
    {
        _toepassinginifile = iniFile;

        InitializeComponent();
    }

    private void button4_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        openFileDialog1.Filter = "Srec Files (.a20; .a21; .a26; .a44)|*.a20; *.a21; *.a26; *.a44|All files (*.*)|*.*";

        openFileDialog1.Title = ("Choose a file");
        openFileDialog1.InitialDirectory = Path.Combine(Directory.GetCurrentDirectory());
        openFileDialog1.RestoreDirectory = true;
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            fileBox.Text = (System.IO.Path.GetFileName(openFileDialog1.FileName));
        }
    }

    private void button3_Click(object sender, EventArgs e)
    {
        toepassing.Name = nameBox.Text;
        toepassing.Controller = controllerComboBox.SelectedItem;
        toepassing.TabTip = descBox.Text;
        toepassing.Lastfile = openFileDialog1.FileName;
        fileBox.Text = openFileDialog1.FileName;


        if (nameBox.Text == "")
            MessageBox.Show("You haven't assigned a Name");
        else if (controllerComboBox.Text == "")
            MessageBox.Show("You haven't assigned a Controller");
        else if (descBox.Text == "")
            MessageBox.Show("You haven't assigned a Desciption");
        else if (fileBox.Text == "")
            MessageBox.Show("You haven't assigned a Applicationfile");
        _toepassinginifile.ToePassingen.Add(toepassing);
        _toepassinginifile.Save();

        MessageBox.Show("Save Succesfull");



        this.Close();
    }

}}

Source 2 The flashloader.toepassing file (This is a Class):

namespace Flashloader{
class Toepassing
{
    private String _name;

    public String Name
    {
        get { return _name; }
        set { _name = value; }
    }

    public Controller Controller = null;
    public String TabTip = "";
    public String Lastfile = "";

  [Obsolete]
  public String Baudrate = "";

  [Obsolete]
  public String Port = "";

  public String Useboot = "";

    public Toepassing()
    {
        Name = "";
    }

    public Toepassing(String naam)
    {
        Name = naam;
    }

    public override String ToString()
    {
        return Name + " :" + TabTip;
    }
}
}

And finally source 3 flashloader.toepassinginifile (Another class):

namespace Flashloader
{
class toepassinginifile
{
    private const String FILE_NAME = "flash.ini";
    private Controllerlist _controllers;
    public Toepassinglist ToePassingen { get; private set; }
    public Settings Settings { get; private set; }


    public toepassinginifile( Controllerlist controllers)
    {
        _controllers = controllers;

        // TODO Startup class maken en laden
        ToePassingen = LoadToepassingen();
    }

    private Toepassinglist LoadToepassingen()
    {
        StringList input = new StringList().FromFile( FILE_NAME );
        Toepassinglist output = new Toepassinglist();

        Settings settings = null;
        Toepassing toepassing = null;

        foreach (var item in input)
        {
            String line = item.Trim();

            if (line.StartsWith("[") && line.EndsWith("]"))
            {
                settings = null;
                toepassing = null;

                String name = line.Substring(1, line.Length - 2);

                if (name.ToUpper().Equals("STARTUP"))
                {
                    Settings = settings = new Settings();
                    continue;
                }
                // TODO kan weg in de toekomst
                if ( name.ToUpper().Equals("DRAG && DROP"))
                {
                    toepassing = null;
                    continue;
                } // */

                toepassing = new Toepassing(name);
                output.Add(toepassing);
            }
            else if (settings != null)
            {
                int index = line.IndexOf('=');
                if (index < 0)
                    continue;

                String key = line.Substring(0, index).Trim();
                String value = line.Substring(index + 1).Trim();

                if (Utils.EqualsIgnoreCase(key, "Baudrate"))
                    Settings.Baudrate = value;
                else if (Utils.EqualsIgnoreCase(key, "Port"))
                    Settings.Port = value;
            }
            else if (toepassing != null)
            {
                int index = line.IndexOf('=');
                if (index < 0)
                    continue;

                String key = line.Substring(0, index).Trim();
                String value = line.Substring(index + 1).Trim();

                if (Utils.EqualsIgnoreCase(key, "TabTip"))
                    toepassing.TabTip = value;
                else if (Utils.EqualsIgnoreCase(key, "Controller"))
                    toepassing.Controller = _controllers.FindByName(value);
                else if (Utils.EqualsIgnoreCase(key, "Lastfile"))
                    toepassing.Lastfile = value;
                else if (Utils.EqualsIgnoreCase(key, "Useboot"))
                    toepassing.Useboot = value;
            }
        }
        return output;
    }

    public void Save()
    {
        StringList list = new StringList();

        Toepassing settings = new Toepassing("[Startup]");

        list.Add("["+settings.Name+"]");
        list.Add("LastUsed=");
        list.Add("Port=" +settings.Port);
        list.Add("Baudrate=" +settings.Baudrate);

        foreach (Toepassing item in ToePassingen)
        {
            list.Add( "[" + item.Name + "]" );
            list.Add( "Controller=" + item.Controller.Name );
            list.Add( "TabTip="+ item.TabTip );
            list.Add("LastFile="+ item.Lastfile);
            list.Add("UseBoot="+ item.Useboot);
        }

        Toepassing dragndrop = new Toepassing("[Drag && Drop]");

            list.Add("["+dragndrop.Name+"]");
            list.Add("Autostart=");
            list.Add("Baudrate="+ dragndrop.Baudrate);
            list.Add("Port="+ dragndrop.Port);
            list.Add("Lasfile="+ dragndrop.Lastfile);

        list.ToFile(FILE_NAME);
    }
}
}

If I could get some help, it would be a lot easier to solve the errors.

FIXED IT


1 Answers

Since toepassinginifile is used on a public method of a public type, it must itself by public (it is currently internal). Change:

class toepassinginifile

to:

public class toepassinginifile

or even better ;p

public class ToePassingIniFile

and likewise for the other, since Toepassing is used as a public field on a public type, Toepassing must itself be public.

Final thought: public fields are rarely a good idea; a public property would be preferable:

private Toepassing toepassing = new Toepassing();
public Toepassing Toepassing  {get { return toepassing; } }
like image 136
Marc Gravell Avatar answered Jul 07 '26 11:07

Marc Gravell