Expression recursively calls the containing property '<propertyname>'

A statement in the Set procedure of a property definition stores a value into the name of the property.

The recommended approach to holding the value of a property is to define a Private variable in the property's container and use it in both the Get and Set procedures. The Set procedure should then store the incoming value in this Private variable.

The Get procedure behaves like a Function procedure, so it can assign a value to the property name and return control by encountering the End Get statement. The recommended approach, however, is to include the Private variable as the value in a Return Statement.

The Set procedure behaves like a Sub procedure, which does not return a value. Therefore, the procedure or property name has no special meaning within a Set procedure, and you cannot store a value into it.

The following example illustrates the approach that can cause this error, followed by the recommended approach.

Public Class illustrateProperties  
' The code in the following property causes this error.  
    Public Property badProp() As Char  
            Dim charValue As Char  
            ' Insert code to update charValue.  
            badProp = charValue  
        End Get  
        Set(ByVal Value As Char)  
            ' The following statement causes this error.  
            badProp = Value  
            ' The value stored in the local variable badProp  
            ' is not used by the Get procedure in this property.  
        End Set  
    End Property  
' The following code uses the recommended approach.  
    Private propValue As Char  
    Public Property goodProp() As Char  
            ' Insert code to update propValue.  
            Return propValue  
        End Get  
        Set(ByVal Value As Char)  
            propValue = Value  
        End Set  
    End Property  
End Class  

By default, this message is a warning. For more information about hiding warnings or treating warnings as errors, please see Configuring Warnings in Visual Basic.

Error ID: BC42026

To correct this error

  • Rewrite the property definition to use the recommended approach as illustrated in the preceding example.

See Also

Property Procedures
Property Statement
Set Statement