Inconsistent Accessibility: Parameter type is less

2019-01-01 07:10发布

I'm trying to pass an object (a reference to the currently logged on user, basically) between two forms. At the moment, I have something along these lines in the login form:

private ACTInterface oActInterface;

public void button1_Click(object sender, EventArgs e)
    {
        oActInterface = new ACTInterface(@"\\actserver\Database\Premier.pad",this.textUser.Text,this.textPass.Text);

        if (oActInterface.checkLoggedIn())
        {
            //user has authed against ACT, so we can carry on
            clients oClientForm = new clients(oActInterface);
            this.Hide();
            oClientForm.Show();
        }
        else...

on the next form (clients), I have:

public partial class clients : Form
{
    private ACTInterface oActInt {get; set;}

    public clients(ACTInterface _oActInt)

...which results in me getting:

Error   1   Inconsistent accessibility: 
parameter type 'support.ACTInterface' is less accessible than method    
'support.clients.clients(support.ACTInterface)'  
c:\work\net\backup\support\support\clients.cs   20  16  support

I don't really understand what the problem is - both fields are private, and accessed by the relevant public method from the form. Googling doesn't really help, as it just points towards one element being public and the other private, which isn't the case here.

Anybody help?

标签: c# object
11条回答
墨雨无痕
2楼-- · 2019-01-01 07:30

If sounds like the type ACTInterface is not public, but is using the default accessibility of either internal (if it is top-level) or private (if it is nested in another type).

Giving the type the public modifier would fix it.

Another approach is to make both the type and the method internal, if that is your intent.

The issue is not the accessibility of the field (oActInterface), but rather of the type ACTInterface itself.

查看更多
若你有天会懂
3楼-- · 2019-01-01 07:30

The problem doesn't seem to be with the variable but rather with the declaration of ACTInterface. Is ACTInterface declared as internal by any chance?

查看更多
千与千寻千般痛.
4楼-- · 2019-01-01 07:30

You can get Parameter (class that have less accessibility) as object then convert it to your class by as keyword.

查看更多
素衣白纱
5楼-- · 2019-01-01 07:39

If this error occurs when you want to use a classvariable in a new form, you should put the class definition in the

Formname.Designer.cs

instead of the Formname.cs file.

查看更多
爱死公子算了
6楼-- · 2019-01-01 07:39

After updating my entity framework model, I found this error infecting several files in my solution. I simply right clicked on my .edmx file and my TT file and click "Run Custom Tool" and that had me right again after a restart of Visual Studio 2012.

查看更多
君临天下
7楼-- · 2019-01-01 07:47

Make the class public.

class NewClass
{

}

is the same as:

internal class NewClass
{

}

so the class has to be public

查看更多
登录 后发表回答