Late-bound default property reference could not be resolved
In Visual Basic 6.0, objects had a default property that could be used as a shortcut in code. For example, the default property of a TextBox control was the Text property; you could type
TextBox1 = "Hello" instead of
TextBox1.Text = "Hello".
In Visual Basic .NET, default properties are no longer supported; all property references must be fully qualified. During upgrade, default properties for early-bound objects are resolved to the property name; however, late-bound objects cannot be resolved because it is impossible to determine a default property without knowing what the object is.
In addition, Visual Basic 6.0 allowed late-bound calls to implemented interfaces of classes; this is no longer allowed in Visual Basic .NET.
The following example shows late-bound code that cannot be resolved:
' Visual Basic 6.0 Dim x As String Dim y As Object x = "Hello" Set y = Form1.Controls(0) y = x Debug.Print y ' After upgrade to Visual Basic .NET Dim x As String Dim y As Object x = "Hello" 'UPGRADE_WARNING: VB.Controls method Controls.Item has a new behavior. y = Form1.DefInstance.Controls(0) ' UPGRADE_WARNING: Couldn't resolve default property of object 'y'. y = x System.Diagnostics.Debug.WriteLine(y)
What to do next
- In many cases, nothing needs to be done. If the warning is given for a primitive type rather than an object, nothing needs to be done.
- If possible, modify your code to use early binding before upgrading to Visual Basic .NET.
- If late binding is necessary, determine the default property for the object and add it to your code. The following example shows how to modify the above code, assuming that
Controls(0)refers to a TextBox control:
Dim x As String Dim y As Object x = "Hello" y = Me.Controls(0).Text y = x Console.WriteLine y