Microsoft KB Archive/316139

= You may receive an error message &quot; is not accessible in this context because it is 'Protected'&quot; when you try to implement an interface in Visual Basic =

Article ID: 316139

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q316139



SYMPTOMS
If you try to implement an interface, you may receive the following error message:

' ' is not accessible in this context because it is 'Protected'.



CAUSE
This behavior occurs because the interface that you are trying to implement is marked as protected in a base class. You cannot implement a protected interface.



STATUS
This behavior is by design.



Steps to reproduce the behavior
 Start Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET. On the File menu, click New, and then click Project. Under Project types, click Visual Basic Projects, click Windows Application under Templates, and then accept the defaults. Form1 is created by default.

Note In Visual Studio 2005, click Visual Basic instead of Visual Basic Projects.

Note You must change the code in Visual Basic 2005. By default, Visual Basic creates two files for the project when you create a Windows Forms project. If the form is named Form1, the two files that represent the form are named Form1.vb and Form1.Designer.vb. You write the code in the Form1.vb file. The Windows Forms Designer writes the code in the Form1.Designer.vb file. The Windows Forms Designer uses the partial keyword to divide the implementation of Form1 into two separate files. This behavior prevents the designer-generated code from being interspersed with your code.

For more information about the new Visual Basic 2005 language enhancements, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx

For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/ms171843.aspx

 Add two classes to the project.  Open the code window for Class1, and then add the following code. Public Class Class1 Protected Interface ITest

End Interface End Class </li>  Open the code window for Class2, and then add the following code. Public Class Class2 Inherits Class1 Implements Class1.ITest End Class You receive the following error message in the Task List:

'WindowsApplication1.Class1.ITest' is not accessible in this context because it is 'Protected'.

</li></ol>

Keywords: kbvs2005swept kbvs2005applies kberrmsg kbprb KB316139

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.