You may receive an error message "<Method> is not accessible in this context because it is 'Protected'" when you try to implement an interface in Visual Basic (316139)



The information in this article applies to:

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

This article was previously published under Q316139

SYMPTOMS

If you try to implement an interface, you may receive the following error message:
' Method' 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.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET.
  2. On the File menu, click New, and then click Project.
  3. 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: For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:
  4. Add two classes to the project.
  5. Open the code window for Class1, and then add the following code.
    Public Class Class1
        Protected Interface ITest
    
        End Interface
    End Class
    					
  6. 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'.

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kberrmsg kbprb KB316139 kbAudDeveloper