PublicClass() is inaccessible due to its protection level
-
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
-
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
A couple things come to mind:
- 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. - 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-----
- 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,
-
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