BUG: You cannot use the Me keyword before the property name in a Visual Basic .NET structure (819354)



The information in this article applies to:

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

SYMPTOMS

If you have a property defined in a Visual Basic .NET structure and you try to assign a value to that property in the same structure by qualifying the property name with the Me keyword, then you receive the following error:
Expression is a value and therefore cannot be the target of an assignment.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

WORKAROUND

To work around this problem, do not qualify the property name with Me when you assign a value to the property in the structure.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, click New, and then click Project.
  3. Under Project types, click Visual Basic Projects.
  4. Under Templates, click Console Application.

    By default, Module1 is created.
  5. In the Code window, replace the existing code with the following code:
    Option Strict On
    
    Module Module1
    
        Public Structure myStruc
            Private strName As String
    
            Public Property myProp() As String
                Get
                    Return strName
                End Get
                Set(ByVal Value As String)
                    strName = Value
                End Set
            End Property
    
            Public Sub CallProperty()
                Me.myProp = "Hello"
            End Sub
        End Structure
    
        Sub Main()
    
        End Sub
    
    End Module
    
    End Module
  6. On the Build menu, click Build Solution.

    You receive the error message described in the "Symptoms" section of this article in the Task List.

REFERENCES

For more information about structures, visit the following MSDN Web site:

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbProperties kberrmsg kbConsole kbprb kbbug KB819354 kbAudDeveloper