BUG: Compile error message when you implement a class in a referenced COM library (316581)



The information in this article applies to:

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

This article was previously published under Q316581

SYMPTOMS

When you implement a class in a referenced Component Object Model (COM) library in Visual Basic .NET or in Visual Basic 2005, you receive the following compile error message:
ClassName must implement 'Overridable Overloads Property PropertyName As Object' for interface ProjectName.ClassName'. Implementing property must have matching 'ReadOnly'/'WriteOnly' specifiers.

'PropertyName' cannot implement PropertyName because there is no matching property on interface 'ClassName'.

CAUSE

This behavior occurs because a class in the COM library exposes one or more public variant variables, or it exposes a public Property Let or Property Set procedure that passes arguments by reference.

RESOLUTION

To resolve this bug, rebuild the COM library so that it passes arguments to property procedures by value instead of by reference, as in the following sample code:
Public Property Let Data(ByVal strDataIn As String)
   strData = strDataIn
End Property
				

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to Reproduce the Problem

  1. Start Microsoft Visual Basic 6.0.
  2. Create a new ActiveX DLL project.
  3. Type the following code in the General Declarations section of the default class module, Class1:
    Private strData As String
    
    Public Property Get Data() As String
       Data = strData
    End Property
    
    Public Property Let Data(strDataIn As String)
       'Note that the strDataIn argument is being passed
       'by reference because neither the ByRef and ByVal keywords 
       'have been declared.
    
       strData = strDataIn
    End Property
    					
  4. On the File menu, click Make Project1.DLL.
  5. Select a location in which to create the project, and then click OK.
  6. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  7. Create a new Visual Basic Class Library project.
  8. On the Project menu, click Add Reference.
  9. On the COM tab, select the Project1 component, click Select, and then click OK.

    Note In Visual Studio 2005, you do not have to click Select.
  10. Add the following code to the default Class1 class module:
    Public Class Class1
       Implements Project1.Class1 'Implements this COM class
    
    End Class
    					
  11. In the Class Name list on the left side of the code window, click Class1 (Project1).
  12. In the Method Name list on the right side of the code window, click Data.

    This automatically adds the following code to the class module to provide the implementation for the Data property:
    Public Property Data() As String Implements Project1.Class1.Data
       Get
       
       End Get
    
       Set (ByVal Value As String)
       
       End Set
    End Property
    					
  13. On the Build menu, click Build Solution. Note the following build errors displayed in the Task list:
    'ClassLibrary1.Class1' must implement 'Overridable Overloads Property Data() As String' for interface 'Project1._Class1'. Implementing property must have matching 'ReadOnly'/'WriteOnly' specifiers.

    'Data' cannot implement 'Data' because there is no matching property on interface 'Class1'.

Modification Type:MajorLast Reviewed:2/16/2006
Keywords:kbvs2005swept kbvs2005applies kbvs2002sp1sweep kbbug kberrmsg kbnofix KB316581