Article ID: 906769 - Last Review: November 22, 2007 - Revision: 2.2
A Visual Basic 6.0 project that was upgraded by using Visual Studio .NET 2003 no longer functions as expected when you click to select the "Enable application framework" check box in Visual Studio 2005
SYMPTOMS
A Microsoft Visual Basic 6.0 project that was upgraded by using Microsoft Visual Studio .NET 2003 no longer functions as expected when you click to select the Enable application framework check box in Microsoft Visual Studio 2005.
Consider the following scenario:
Consider the following scenario:
- You have a Standard EXE project that was created by using Visual Basic 6.0.
- You have upgraded the Standard EXE project to a Microsoft Windows Forms project by using Visual Studio .NET 2003.
- Then, you have recompiled the upgraded Windows Forms project in Visual Studio 2005.
- If you use the Form1.DefInstance.PropertyName property to reference a form property of the default instance of a startup form, any changes to the property do not take effect.
- If you use the Form1.DefInstance.MethodName method to reference a method, any method that you call on the default instance of a startup form does not work as excepted.
CAUSE
This problem may occur in the scenario that is mentioned in
the "Symptoms" section if you enable the Enable application
framework option in Visual Studio 2005.
The Visual Basic Upgrade tool adds a Try/Catch block to the New constructor in the project. When the Enable application framework option is enabled, the If statement in this Try/Catch block no longer evaluates to True in Visual Studio 2005.
The following code example shows the Try/Catch block that contains the If statement.Because of this behavior, the m_vb6FormDefInstance = Me statement in the form's New constructor cannot run when the startup form is being
initialized. Therefore, the m_vb6FormDefInstance variable does not point to the default instance of the startup
form after the startup form has been initialized.
When you first use the Form1.DefInstance property later in the code, a new form is created. Additionally, the m_vb6FormDefInstance variable is set to point to this new form. Any later calls to the Form1.DefInstance property will return a reference to this new form instead of a reference to the startup form.
The Visual Basic Upgrade tool adds a Try/Catch block to the New constructor in the project. When the Enable application framework option is enabled, the If statement in this Try/Catch block no longer evaluates to True in Visual Studio 2005.
The following code example shows the Try/Catch block that contains the If statement.
Public Sub New()
…
Try
'For the startup form, the first instance that is created is the default instance.
If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
m_vb6FormDefInstance = Me
End If
Catch
End Try
…
End Sub
When you first use the Form1.DefInstance property later in the code, a new form is created. Additionally, the m_vb6FormDefInstance variable is set to point to this new form. Any later calls to the Form1.DefInstance property will return a reference to this new form instead of a reference to the startup form.
RESOLUTION
To resolve this problem, change the old logic from the If
statement to appear similar to the following code example.
If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Or _
System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is My.Application.GetType Then
m_vb6FormDefInstance = Me
End If
STATUS
Microsoft
has confirmed that this is a problem in the Microsoft products that are listed
in the "Applies to" section.
REFERENCES
For more information about the Object.GetType method, visit the following Microsoft
Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/system.object.gettype(vs.71).aspx
(http://msdn2.microsoft.com/en-us/library/system.object.gettype(vs.71).aspx)
For more information about the MemberInfo.DeclaringType property, visit the following MSDN Web site:http://msdn2.microsoft.com/en-us/library/system.reflection.memberinfo.declaringtype(vs.71).aspx
(http://msdn2.microsoft.com/en-us/library/system.reflection.memberinfo.declaringtype(vs.71).aspx)
Note: This article is from Microsoft Knowledage Base
Related problems posted by other users | |
| more... |

