Public class is inaccessible due to its protection level

This error is a result of the protection level of ClassB's constructor, not ClassB itself. Since the name of the constructor is the same as the name of the class* , the error may be interpreted incorrectly. Since you did not specify the protection level of your constructor, it is assumed to be internal by default. Declaring the constructor public will fix this problem:

public ClassB() { } 

* One could also say that constructors have no name, only a type; this does not change the essence of the problem.

Also if you want to do something like ClassB.Run("thing");, make sure the Method Run(); is static or you could call it like this: thing.Run("thing");.

You could go into the designer of the web form and change the "webcontrols" to be "public" instead of "protected" but I'm not sure how safe that is. I prefer to make hidden inputs and have some jQuery set the values into those hidden inputs, then create public properties in the web form's class (code behind), and access the values that way.


  1. Canaan

    • 2016/6/11

    This error is a result of the protection level of ClassB 's constructor, not ClassB itself. Since the name of the constructor is the same as 

  2. Rossetti

    • 2019/8/26

    Public Class - "is inaccessible due to its protection level. Only public types can be processed." Public class is inaccessible due to its protection level. 0.

  3. Abazi

    • 2017/12/9

    Just declare the method as public : C#. Copy Code. public static void greet() More info on accessibility levels:

  4. Karter

    • 2017/4/9

    public partial class EnergizerMaster : System.Web.UI.Page { protected void btnSave_Click(object sender, EventArgs e) { Energizerentity objEnergizerentity = new Energizerentity(); int res = objEnergizerentity.AddEnergizer(args); } } The compiler says that Energizerentity is inaccessible due to its protection level.

  5. Ace

    • 2016/5/12

    I've written the following code in a separate c# project: public class Energizerentity { public System.Data.DataTable GetEnergizerList(int count) 

  6. Abel

    • 2021/6/2

    public class TCard { int suit; int rank; } and later i've got this method, which throws a bunch of errors. Identifiers highlighted with the double asterixes throw the "is innaccessible due to its protection level" error. I've tried rebuilding my solution, and this hasn't worked.

  7. Marcelo

    • 2015/8/25

    Default access is private , so making your properties public will solve this. public class TCard { public int suit; public int rank; }.

  8. Hunter

    • 2016/6/9

    Solution 1. Edit: re-reading your code carefully, when you define a method as static, you don't access it from an instance of the class, but from the class itself. So you have two choices: This is the most sensible way, since a) you do not use any instance variable in the method. b) This simplifies the usage of the method (you don't have to

  9. Morgan

    • 2015/7/10

    By adding the public access modifier to the base constructor, the error went away. public class TreeViewModel : INotifyPropertyChanged { public 

  10. Marcel

    • 2019/1/1

    I am folowing MusicStore Tutorial and as I was on page 48 with this code. public class StoreController : Controller { MusicStoreEntities storeDb = new MusicStoreEntities(); // // GET: /Store/ public ActionResult Index() { var genres = storeDb.Genres.ToList(); return View(genres); } I am getting a redline under Genre and as i put cursor on it it saying "inaccessible due to its protection level".

  11. Tanner

    • 2015/12/12

    You have a static method 'hello()' within a public class 'hellow' wrapped in a namespace 'prog'. You can access it as: hellow.hello(); or prog.

  12. Judson

    • 2016/12/16

    Consumers of this interface are not guaranteed to have access to the method. You need to change the properties of a button from private to public. You can change under button>> properties>> design>> modifiers>> "public" After changing the protection, the error will disappear. answered Dec 5, 2020 amna 113k. points.

  13. Reuben

    • 2019/11/28

    Public class inaccessible due to protection level Your Player and User class have no access modifier specified, and as a result they're internal by default.

  14. Rhett

    • 2017/12/27

    The error I'm getting is "BC30451: 'ds' is not declared. It may be inaccessible due to its protection level" Public Sub getSalesByClienttoAmend() Dim ds As New DataSet() Dim dt As New DataTable Dim conn As SqlConnection Dim sDA As New SqlDataAdapter() Dim connectionString As String = ConfigurationManager.ConnectionStrings("abc123").ConnectionString

  15. Reginald

    • 2015/11/10

    What I'm not getting is that Hangman is a public class so why if it's called in the namespace why its throwing this. Thank for any help.

  16. Taylor

    • 2016/12/29

    The solution. If that happens we only need to make sure that the Resource class containing our translations is public (as opposed to define it 

  17. Canaan

    • 2021/4/5

    C# "is inaccessible due to its protection level" ошибка в конструкторе namespace Encrypter { class Cipher { public Cipher(string name, string type) 

Comments are closed.

Recent Posts