BUG: "Public Overrides WriteOnly Property..." error when you try to override a Microsoft Visual Basic 6.0 property in Microsoft Visual Basic .NET (818216)
The information in this article applies to:
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
SYMPTOMSYou have a Microsoft Visual Basic 6.0 class that has a
property with the ByRef parameter. When you inherit the class in Visual Basic .NET and
override the property, you receive the following compilation error:
'Public Overrides WriteOnly Property myProp() As
System.IntPtr' cannot override 'Public Overridable Overloads WriteOnly Property
myProp() As System.IntPtr' because they differ by their return
types. CAUSEThe .NET runtime compares the return types of the parameters
in the base class and inherited class property. This comparison returns a
difference in the return types while it compares the symbols for System.IntPtr and System.Int16. Two separate symbols represent these internally. This results in
an error.WORKAROUNDTo work around this bug, pass the argument as ByVal instead of as ByRef in the base class. If you pass the argument as ByVal, actual data is copied instead of a pointer to the data.
The following code sample describes how to pass the argument as ByVal: Option Explicit
Private m_intNumber As Integer
'Previous Implementation
'Public Property Let myProp(ByRef intNumber As Integer)
' m_intNumber = intNumber
'End Property
'New Implementation
Public Property Let myProp(ByVal intNumber As Integer)
m_intNumber = intNumber
End Property
Public Function ReturnNumber() As Integer
ReturnNumber = m_intNumber
End Function STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.REFERENCESFor more information about overriding properties and
methods, visit the following MSDN Web site:
Modification Type: | Minor | Last Reviewed: | 2/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbProperties kbMarshal kbinterop kbCodeGen kberrmsg kbWndwClass kbprb kbbug KB818216 kbAudDeveloper |
---|
|