Export (0) Print
Expand All
Expand Minimize

Object could not be resolved because it was within a generic namespace

Visual Studio .NET 2003

In Visual Basic 6.0 you could use the ActiveForm property of a Forms collection to refer to controls on the currently selected form; controls were actually treated as properties of the form. In Visual Basic .NET, ActiveForm is a generic type that has no controls. For example, the following code works in Visual Basic 6.0 but cannot compile after being upgraded to Visual Basic .NET:

' Visual Basic 6.0 
MDIForm1.ActiveForm!Label1.Caption = "Active"

' After upgrade to Visual Basic .NET
' Causes a compilation error.
MDIForm1.DefInstance.ActiveMDIChild.Label1.Caption = "Active"

What to do next

  • Modify your code to refer to the underlying form object:
    ' Modified Visual Basic .NET code
    CType(MDIForm1.DefInstance.ActiveMDIChild, Form1).Label1.Text = "Active"
    Note   Using the CType function makes this late bound. The original code in this example is problematic because it assumes that the ActiveForm property will always have a label named Label1 — if Label1 does not exist, a run-time error will occur.

See Also

Screen Object Changes in Visual Basic .NET | Forms Collection Changes in Visual Basic .NET

© 2015 Microsoft