0
votes

I am having a weird error in c#. My code gives the error "Inconsistent accessibility: field type 'Rotanet.RN_BUDGET_SETTINGS' is less accessible than field 'Rotanet.BudgetSettingsDetailFrm.aBudgetSettings'" . I know it is about PUBLIC/PROTECTED/PRIVATE things but I couldnt understand what I should do to fix it.

here is my code that gives the error

namespace Rotanet
{
  public partial class BudgetSettingsDetailFrm : DevExpress.XtraEditors.XtraForm
  {
    public RN_BUDGET_SETTINGS aBudgetSettings = null; //***** this gives the error

    public BudgetSettingsDetailFrm()
    {
        InitializeComponent();
    }

    private void btnSave_Click(object sender, EventArgs e)
    {

    }
  }
}

and the RN_BUDGET_SETTINGS is a simple class like below...

namespace Rotanet
{
  class RN_BUDGET_SETTINGS : RN_AUDIT
  {

    public RN_BUDGET_SETTINGS()
    {
    }
    #region Properties
    [IsKey(true)]
    public dynamic ID { get; set; }
    public dynamic TANIM { get; set; }
    public dynamic DEGER { get; set; }
    #endregion

  }
}

How can I fix this problem

4

4 Answers

5
votes

You need to define the RN_BUDGET_SETTINGS class as being Public:

public class RN_BUDGET_SETTINGS : RN_AUDIT
{

}

or define the aBudgetSettings as internal/private:

private RN_BUDGET_SETTINGS aBudgetSettings = null;

Your problem is that you have defined a public field so it is visible outside your project, however the class that you can read/write to the field isn't public. Externally this means you can set a value, but you've not been told the contract/information about the thing you can set.

1
votes

Classes are internal by default where no access modifier is specified. You need to make RN_BUDGET_SETTINGS public:

public class RN_BUDGET_SETTINGS : RN_AUDIT
{
   public RN_BUDGET_SETTINGS()
   {
   }
   #region Properties
   [IsKey(true)]
   public dynamic ID { get; set; }
   public dynamic TANIM { get; set; }
   public dynamic DEGER { get; set; }
   #endregion
}
1
votes

Class RN_BUDGET_SETTINGS is not marked with any access modifier, so it receives the default access for classes, which is internal.

http://msdn.microsoft.com/en-us/library/ms173121.aspx

"Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified."

1
votes

Because class is Internal by default. change

class RN_BUDGET_SETTINGS : RN_AUDIT

to

public class RN_BUDGET_SETTINGS : RN_AUDIT