Microsoft KB Archive/313519

= BUG: You receive an &quot;Unexpected error in Microsoft Visual Macros. It is safe to save your work and restart both Visual Studio Macros and Visual Studio&quot; error message and Visual Studio macros fail when you close a modeless Windows form in Visual Studio =

Article ID: 313519

Article Last Modified on 1/26/2006

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition

-



This article was previously published under Q313519



SYMPTOMS
Modeless Windows Forms that use the Show method to make the form visible may cause Visual Studio macros to fail.

Code such as the following causes the macros to fail: Public Module Module1 Sub MyTest Dim f1 As Form f1 = New Form f1.Width = 500 f1.Height = 500 f1.Show End Sub The form does not appear correctly and is unresponsive. When you close the form, you receive the End Program dialog box, which includes the End Task button. When you close the form, you may receive the following error message:

Unexpected error in Microsoft Visual Macros. It is safe to save your work and restart both Visual Studio Macros and Visual Studio



RESOLUTION
To fix this problem, add the following code: While ( .Visible) Application.DoEvents End While This code flushes the message queue so that the form can be closed correctly. The code should be inserted after the Show method. The complete code will be similar to the following: Imports System.Diagnostics Imports System.Drawing Imports System.Windows.Forms

Public Module Module1 Sub MyTest Dim f1 As Form f1 = New Form f1.Width = 500 f1.Height = 500 f1.Show While (f1.Visible) Application.DoEvents End While End Sub



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
After you experience the symptoms that are described in this article, the Visual Studio and Visual Studio Macro integrated development environments both appear to be fully functional. You can use them to modify code and save changes. However, subsequent attempts to run the macro that failed initially will fail also, and no error message will appear. If you unload the macro and attempt to reload it, the following error message appears:

Cannot load macro project ' ' for the following reason:

A project with the name ' ' already exists.

You must restart both the Visual Studio and the Visual Studio Macro integrated development environments you can run the macro.

Additional query words: kbreadme

Keywords: kbtshoot kbbug kbvs2002sp1sweep kbvs2005swept kbvs2005doesnotapply KB313519

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.