Microsoft KB Archive/897298

= You receive an &quot;unhandled exception of type 'System.Runtime.InteropServices.SEHException'&quot; error message when you call the Application.EnableVisualStyles method in Visual Basic 2005 or in Visual Basic .NET =

Article ID: 897298

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-





SYMPTOMS
In Microsoft Visual Basic 2005 and in Microsoft Visual Basic .NET, when you call the Application.EnableVisualStyles method from the Form_Load event or from any other event, you receive an error message that is similar to the following:

An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in system.windows.forms.dll

Note This issue occurs when the following conditions are true:
 * The event calls the Application.EnableVisualStyles method again.
 * The event calls the Application.EnableVisualStyles method when a form loads or after a form loads.



WORKAROUND
To work around this issue, use one of the following methods:   Reorganize your code so that you only call the EnableVisualStyles method one time before you load any form. The following code example illustrates how to organize your code: Public Sub Main Application.EnableVisualStyles Application.Run(New frmMain)        'Note: The frmMain form is the first form to open.

End Sub  Create and then add an XML manifest file as a resource that enables your application to use visual styles. To do this, follow these steps:  Link to ComCtl32.lib, and then call the InitCommonControlsEx function.  Add a file that is named  that has the XML manifest format to the source tree. The source tree must be similar to the following code example:    Type your application description here.     </dependentAssembly> </li>  Add the XML manifest to the resource file of your application by using the following code example: CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST &quot;YourApp.exe.manifest&quot; Note You must add this line of code on one line. Alternatively, you can put the XML manifest file in the same folder as the executable file of your application. The operating system loads the XML manifest from the file system. Then, the operating system examines the resource section of the executable file. The file system version takes precedence. </li></ol> </li></ul>

<div class="moreinformation_section">

MORE INFORMATION
You may receive the same error message that is discussed in the &quot;Symptoms&quot; section when you use the ShowDialog method to open a form. To work around this behavior, use the Show method instead of the ShowDialog method.

Keywords: kbvs2005swept kbvs2005applies kbprb KB897298

-

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

© Microsoft Corporation. All rights reserved.