Compiler Error CS1527
Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal
Type declarations in a namespace can have either public or internal access. If no accessibility is specified, internal is the default.
The following sample generates CS1527:
// CS1527.cs
namespace Sample
{
private class C1 {}; // CS1527
protected class C2 {}; // CS1527
protected internal class C3 {}; // CS1527
}
The following example generates CS1527 because when no namespace is explicitly declared in your program code, all type declarations are located implicitly within the global namespace.
//cs1527_2.cs
using System;
protected class C4{}
private struct S1{}
Watch out for this error in the .Designer.ext file as well
This error can be misleading - shown in the Visual Studio "Error List" and indicating a line of code in the Code portion of a Form or other visual component of your project. If you have corrected this error by declaring the Class "public" once again, and the error still gets thrown, then search for all References to that class, and when you find the one in the file whose name is Class.Designer.cs (or Class.Designer.vb), correct the non-"public" modifier for the Class in that file as well. Then all should be working again.
- 6/13/2008
- Mike Smith-Lonergan