开发者

Class is inaccessible due to its protection level

I have three classes. all are part of the same namespace. here are the basics of the three classes.

//FBlock.cs
namespace StubGenerator.PropGenerator
{
    class FBlock : IDesignRegionInserts, IFormRegionInserts, IAPIRegionInserts,  IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts
    {
        private List<Property> pProperties;
        private List<Method> pMethods;
       开发者_运维问答 public FBlock(string aFBlockName)
        { 
            pProperties = new List<Property>();
            pMethods = new List<Method>();
        }

        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<StubGenerator.PropGenerator.PropertyAttribute> pPropertyAttributes;
         private string pName;
         private string pFBlockName;

         public Method(FBlock aFBlock,string aName)
         {
             pPropertyAttributes = new List<PropertyAttribute>();
             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<PropertyAttribute>();
             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);
         }
     }
}

I'm getting the following errors

'StubGenerator.PropGenerator.Method' is inaccessible due to its protection level

which refers to the following line in the FBlock.cs file

private List<Method> pMethods;

and

'StubGenerator.PropGenerator.Method' is inaccessible due to its protection level

which refers to the following line in the FBlock.cs file

 public Method AddMethod(string aName)

and

Inconsistent accessibility: return type 'StubGenerator.PropGenerator.Method' is less accessible than method 'StubGenerator.PropGenerator.FBlock.AddMethod(string)'

which refers to the following line in the FBlock.cs file

 public Method AddMethod(string aName)

making the class Method public does not resolve the errors. I can't figure out why I don't get the errors when calling the Property class. And I don't understand why making the Method class public doesn't fix the problem.

Any ideas?

Edited to ask. could there be some setting on the file that causes this?


First thing, try a full rebuild. Clean and build (or just use rebuild). Every once in a long while that resolves bizarre build issues for me.

Next, comment out the rest of the code that is not in your example you have posted. Compile. Does that work?

If so, start adding segments back until one breaks it.

If not, make all the classes public and try again.

If that still fails, maybe try putting the trimmed down classes in the same file and rebuilding. At that point, there would be absolutely no reason for access issues. If that still fails, take up carpentry.


There was a project that used linked files. I needed to add the method.cs file to that project as a linked file as well, since the FBlock.cs file was there. I've never heard of linked files before, I didn't even know that was possible.


Try adding the below code to the class that you want to use

[Serializable()]
public partial class Class
{


It may also be the case that the library containing the class in question is not properly signed with a strong name.


The code you posted does not produce the error messages you quoted. You should provide a (small) example that actually exhibits the problem.


All your classes are internal by default

Marking public did not do the trick.

Are you sure you do not have two classes named Method, and perhaps are including the wrong Method class?


I'm guessing public Method AddMethod(string aName) is defined on a public interface that FBlock implements. Consumers of that interface are not guaranteed to have access to Method.


Hi You need to change the Button properties from private to public. You can change Under Button >> properties >> Design >> Modifiers >> "public" Once change the protection error will gone.

Budi


your class should be public

public class FBlock : IDesignRegionInserts, IFormRegionInserts, IAPIRegionInserts, IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜