由于其保护级别,类无法访问

我有三节课。 all都是同一命名空间的一部分。 这是三个类的基础知识。

//FBlock.cs namespace StubGenerator.PropGenerator { class FBlock : IDesignRegionInserts, IFormRegionInserts, IAPIRegionInserts, IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts { private List pProperties; private List pMethods; public FBlock(string aFBlockName) { pProperties = new List(); pMethods = new List(); } public Property AddProperty(string aName) { Property loProp = new Property(this, aName, pProperties.Count); pProperties.Add(loProp); return loProp; } public Method AddMethod(string aName) { Method loMeth = new Method(this, aName); pMethods.Add(loMeth); return loMeth; } } //Method.cs namespace StubGenerator.PropGenerator { class Method : IPropertyName { private List pPropertyAttributes; private string pName; private string pFBlockName; public Method(FBlock aFBlock,string aName) { pPropertyAttributes = new List(); pName = aName; pFBlockName = aFBlock.Name; } } } //Property.cs namespace StubGenerator.PropGenerator { class Property : StubGenerator.PropGenerator.IPropertyName, StubGenerator.PropGenerator.IDesignRegionInserts, StubGenerator.PropGenerator.IFormRegionInserts, IAPIRegionInserts, IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts { private string pName; private string pExpandedName; private string pFBlockInitials; private Group pPropertyGroup; private FlowLayoutPanel pGroupFlowPanel; private Button pUpdateButton; private CheckBox pShowProperty; private string pFBlockName; public Property(FBlock aFBlock, string aName, int aIndex) { pPropertyAttributes = new List(); pFBlockName = aFBlock.FBlockName; ExpandName(); GetInitials(); pShowProperty = new CheckBox(this, 10, (aIndex + 1) * 20, aIndex); pPropertyGroup = new Group(this); pGroupFlowPanel = new FlowLayoutPanel(this); pUpdateButton = new Button(this, 10, 18, aIndex); } } } 

我收到以下错误

由于其保护级别,“StubGenerator.PropGenerator.Method”无法访问

它引用FBlock.cs文件中的以下行

 private List pMethods; 

由于其保护级别,“StubGenerator.PropGenerator.Method”无法访问

它引用FBlock.cs文件中的以下行

  public Method AddMethod(string aName) 

可访问性不一致:返回类型’StubGenerator.PropGenerator.Method’比方法’StubGenerator.PropGenerator.FBlock.AddMethod(string)’更难访问

它引用FBlock.cs文件中的以下行

  public Method AddMethod(string aName) 

使类Method公开不解决错误。 我无法弄清楚为什么我在调用Property类时没有得到错误。 我不明白为什么将Method类设为public并不能解决问题。

有任何想法吗?

编辑问。 可能会有一些文件设置导致这个?

首先,尝试完全重建。 清理和构建(或仅使用重建)。 每隔一段时间,我就能解决奇怪的构建问题。

接下来,注释掉您发布的示例中没有的其余代码。 编译。 那样有用吗?

如果是这样,请开始添加片段,直到打破它。

如果没有,请将所有类public然后重试。

如果仍然失败,可以尝试将修剪后的类放在同一个文件中并重建。 那时,绝对没有理由存在访问问题。 如果仍然失败,请从事木工。

有一个项目使用链接文件。 我需要将method.cs文件作为链接文件添加到该项目,因为FBlock.cs文件就在那里。 我以前从未听说过链接文件,我甚至都不知道这是可能的。

尝试将以下代码添加到要使用的类中

 [Serializable()] public partial class Class { 

也可能是包含有关类的库未使用强名称正确签名的情况。

您发布的代码不会生成您引用的错误消息。 您应该提供一个实际显示问题的(小)示例。

默认情况下,所有类都是internal

标记public没有做到这一点。

你确定你没有两个名为Method的类,也许包括错误的Method类?

我猜public Method AddMethod(string aName)是在FBlock实现的公共接口上定义的。 该接口的使用者无法保证可以访问Method。

您好需要将Button属性从私有更改为公共。 您可以更改Under Button >>属性>> Design >> Modifiers >>“public”一旦更改,保护错误就会消失。

布迪