Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. PublicClass() is inaccessible due to its protection level

PublicClass() is inaccessible due to its protection level

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CJOakwood
    wrote on last edited by
    #1

    I have this 3rd part DLL that when viewing in the Object Browser, the Class that I want to work with it public [public class PublicClass : System.Object]. When I set an object to the class [PublicClass myPublicClass = new PublicClass] I get the Compiler Error CS0122 [Class is inaccessible due to its protection level] What seems to be the problem? Any help would be great. Thx

    H L 2 Replies Last reply
    0
    • C CJOakwood

      I have this 3rd part DLL that when viewing in the Object Browser, the Class that I want to work with it public [public class PublicClass : System.Object]. When I set an object to the class [PublicClass myPublicClass = new PublicClass] I get the Compiler Error CS0122 [Class is inaccessible due to its protection level] What seems to be the problem? Any help would be great. Thx

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      A couple things come to mind:

      1. While the class is public, the default constructor might not be (or whatever constructor you're using). If you don't specify a default constructor, it is inherited (access modifier and all) from its parent. In your case, System.Object already has a public default constructor so you're class will inherit that unless overridden.
      2. You may have a type name clash, and the compiler is choosing one over the other. It usually spits out warnings or errors, but who knows sometimes. Make sure you don't have a similarily named class from another imported namespace

      Most likely, the problem is #1 above. The documentation for the C# compiler error CS0122 affirms such.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      1 Reply Last reply
      0
      • C CJOakwood

        I have this 3rd part DLL that when viewing in the Object Browser, the Class that I want to work with it public [public class PublicClass : System.Object]. When I set an object to the class [PublicClass myPublicClass = new PublicClass] I get the Compiler Error CS0122 [Class is inaccessible due to its protection level] What seems to be the problem? Any help would be great. Thx

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        If its a nested class it inherits the enclosing type accessablity. The same rules that are valid for type members are valid for nested types to. leppie::AllocCPArticle("Zee blog");
        Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups