I’ve placed a static class TestClass in the App_Code folder. The class contains a static method TestMethod. From Default.aspx.cs via Button_Click method, I’m trying to invoke TestMethod. – test = TestClass.TestMethod().
This gives error: ‘TestClass’ is inaccessible due to its protection level.
It feels like the static class and the _Default class should be placed into a common namespace, but this would “exclude” the Default.aspx controls references.
What am I doing wrong?
You need to declare
TestClassas public:The default visibility is
internalfor types andprivatefor members of a type definition. TheApp_Codefolder gets compiled into its own assembly, different from the assembly that is created when compiling the code behinds.internaltypes cannot be shared between assemblies (that’s not 100% true but true in this case), hence why you are having this problem.