- INDEX VB TO NET
- KNOWLEDGE BASE
- EWIS-WARNINGS
- WARNING #1037
WARNING #1037
Couldn't resolve default property of object %1.
Description
When using Object and Variant the behavior on assigment is defined by the default property of the object being handled due to late binding (or soft binding). This is a runtime operation, which cannot be reliable migrated.
When this EWI is displayed the target source code may require some manual adjustments to determine the default property used for the given statement.
Recommendations
Use of strong typing in the original source code and removal of late-binding scenarios can mitigate the occurrence of this EWI.
For example, in some cases code such as:
frm.Label2 = Another Test"
The default property Caption of the Label control will be used for the assignment, however, this is not apparent during migration and it would be much clearer if the statement is replaced with:
frm.Label2.Caption = Another Test"
This particular example of the EWI 1037 results from an Array and Collection both being assigned to a Variant. In these cases a workaround cannot be applied, and a manual fix will be required. The migration consultant will need to determine the intended property and dependencies. However, one should consider possible all possible runtime values when determining the default properties.
Sample VB6
Option Base 1
Public Sub ProcedureExpected(condition As Boolean)
Dim v As Variant
If condition Then
Set v = New Collection
v.Add "mock value #1"
v.Add "mock value #2"
Else
v = Array(1, 2)
End If
MsgBox v(1)
MsgBox v(2)
End Sub
Target VB.NET
PublicSub ProcedureExpected(ByRef condition AsBoolean)
Dim v AsObject
If condition Then
v = NewObject
v.Add("mock value #1")
v.Add("mock value #2")
Else
'UPGRADE_WARNING: (1037) Couldn't resolve default property of object v.
v = NewObject() {1, 2}
EndIf
MessageBox.Show(CStr(v.GetValue(1)), Application.ProductName)
MessageBox.Show(CStr(v.GetValue(2)), Application.ProductName)
EndSub
Expected VB.NET
PublicSub ProcedureExpected(ByRef condition AsBoolean)
Dim v As ArrayList
If condition Then
v = New ArrayList()
v.Add("mock value #1")
v.Add("mock value #2")
Else
v = New ArrayList(NewObject() {1, 2})
EndIf
MessageBox.Show(CStr(v(0)), Application.ProductName)
MessageBox.Show(CStr(v(1)), Application.ProductName)
EndSub
Target C#
staticpublicvoid ProcedureExpected( bool condition)
{
object v = null;
if (condition)
{
v = newobject();
v.Add("mock value #1");
v.Add("mock value #2");
} else
{
//UPGRADE_WARNING: (1037) Couldn't resolve default property of object v.
v = newobject[]{1, 2};
}
MessageBox.Show(Convert.ToString(((Array) v).GetValue(1)), Application.ProductName);
MessageBox.Show(Convert.ToString(((Array) v).GetValue(2)), Application.ProductName);
}
Expected C#
staticpublicvoid ProcedureExpected(bool condition)
{
ArrayList v = null;
if (condition)
{
v = newArrayList();
v.Add("mock value #1");
v.Add("mock value #2");
}
else
{
v = newArrayList(newobject[] { 1, 2 });
}
MessageBox.Show(Convert.ToString(v[0]), Application.ProductName);
MessageBox.Show(Convert.ToString(v[1]), Application.ProductName);
}