我试图在两个表单之间传递一个对象(基本上是对当前登录用户的引用)。目前,我在登录表单中有一些东西:

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...

在下一个表格(客户)上,我有:

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

    public clients(ACTInterface _oActInt)

...这导致我得到:

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

我真的不明白问题是什么-这两个字段都是私有的,并且由相关的公共方法从表单访问。谷歌搜索并没有真正的帮助,因为它只是指出一个元素是公共的,另一个是私有的,这不是这里的情况。

有人帮助吗?


当前回答

在更新实体框架模型后,我发现这个错误感染了解决方案中的几个文件。我简单地右键单击我的。edmx文件和我的TT文件,然后单击“运行自定义工具”,这让我在重新启动Visual Studio 2012后再次正确。

其他回答

类型的类定义中,如果要在新表单中使用类变量时发生此错误

Formname.Designer.cs

而不是Formname.cs文件。

parameter type 'support.ACTInterface' is less accessible than method    
'support.clients.clients(support.ACTInterface)' 

错误显示“支持”。ACTInterface'的可访问性较差,因为你已经将接口设置为私有,至少将其设置为内部或公共。

在我的情况下,我在一个文件中已经完成类,我在另一个文件中传递该类的构造函数的实例。 问题是在声明类时没有使用公共修饰符:

我可以把它改成公共类MyClass {}

公共类客户端的构造函数是公共的,但它有一个类型为ACTInterface的参数是私有的(它嵌套在类中?)你不能这么做。您需要使ACTInterface至少像客户机一样可访问。

试着让你的构造函数像这样私有:

private Foo newClass = new Foo();