Ramblings & Controls from a .NET Addicted Freak!

Kevin Gearing's Blog


Argh! Just when my application was starting to look really good I come across the dreaded "System.Runtime.InteropServices.SEHException".

For those of you who don't know, this tends to happen if you make use of Application.EnableVisualStyles() to give your program the XP look 'n' feel, or in my case if you're using Skybounds excellent VisualStyles component ( and start opening Dialog windows.

Whilst removing Application.EnableVisualStyles() or using a Manifest file will fix the problem, I'd lose the themed tabs and other controls that I've come to love...

Fortunately this is only happening with one particular window, so as a quick and simple hack I simply added a Timer control (has to be System.Timers.Timer as System.Windows.Forms.Timer doesn't solve the problem) to the parent window, set Timer.Interval to 100 and Timer.Enabled to False. Then moved my code from the 'problem' eventhandler to the Timer.Elapsed event and added Timer.Stop on the first line. Then back in the original eventhandler I added Timer.Start. The result? Problem fixed.

Hopefully this will be resolved in Whidbey.



Bradley Uffner said:

.EnableVisualStyles, then immediatly after call Application.DoEvents. This should be done from a Sub Main BEFORE and forms or controls are instanciated.
September 13, 2004 6:41 PM

Kevin Gearing said:


Application.DoEvents() doesn't actually solve the problem.

In the situation I had, I have a Startup module which performs various actions, including setting Application.EnableVisualStyles() way before instantiating any forms or controls.

The problem with Visual Styles in .NET Framework 1.1 is a confirmed bug and will be resolved in Whidbey. There is also talk of having a managed UxTheme wrapper.
September 16, 2004 2:20 PM

Venkat said:


I have the same problem when i invoke a form object, from another form, i am not able to fix the bug as it runs to the end of the main() , is there a way to fix the bug.

June 20, 2005 4:17 PM

cadessi said:


AFAIK, Skybound VisualStyles gives theme support to tabcontrols and tabPages; indeed i think it will give theme support to everycontrol. Anyway, i could remove Application.EnableVisualStyles() line without suffer any loss.
February 6, 2006 3:59 PM

dinkelburt said:

Well I'll be damned... works like a charm, thanks much!
September 28, 2006 12:15 AM

Rag said:


We are getting same exception through from a form which posts its records to MSMQ Client Queue.

We do not have Application.EnableVisualStyles() method being called in our application.


A fatal error happened in

Exception type: System.Runtime.InteropServices.SEHException

Exception message:
External component has thrown an exception.

Exception stacktrace:
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmUpdateUIState(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.ParkingWindow.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
April 17, 2007 6:27 AM

henok said:

i am trying to access parallel port but as i do i donwnloaded inpout32.dll to location in windows/system and even windows/system32 in my xp pc.But the error occurs when my program calls the software "System.Runtime.InteropServices.SEHException"

please help me>>>>>

May 17, 2008 11:12 PM

Message: External component has thrown an exception. Exception Type: System.Runtime.InteropServices.SEHException « Amir’s notebook said:

Pingback from  Message: External component has thrown an exception. Exception Type: System.Runtime.InteropServices.SEHException « Amir’s notebook

March 17, 2009 5:53 AM

Ben said:

I get the same error... only it has nothing to do with forms. Check this out... "stepping into" any method with a "decimal" in the input parameter, or as the result type, when debugging a Unit Test (yes folks, all those circumstances needs to be met) raises this error ... and is completely screwing me!

April 1, 2009 9:44 PM

Circass said:

System.Runtime.InteropServices.SEHException was unhandled

 Message="Dış bileşen özel durum oluşturdu."




      konum: UzaktanKumanda.Form1.Output(Int32 adress, Int32 value)

      konum: UzaktanKumanda.Form1.button1_MouseDown(Object sender, MouseEventArgs e) C:\Users\Circass\Documents\Visual Studio 2008\Projects\UzaktanKumanda\UzaktanKumanda\Form1.cs içinde: satır 36

      konum: System.Windows.Forms.Control.OnMouseDown(MouseEventArgs e)

      konum: System.Windows.Forms.ButtonBase.OnMouseDown(MouseEventArgs mevent)

      konum: System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)

      konum: System.Windows.Forms.Control.WndProc(Message& m)

      konum: System.Windows.Forms.ButtonBase.WndProc(Message& m)

      konum: System.Windows.Forms.Button.WndProc(Message& m)

      konum: System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

      konum: System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

      konum: System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

      konum: System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

      konum: System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

      konum: System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

      konum: System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

      konum: System.Windows.Forms.Application.Run(Form mainForm)

      konum: UzaktanKumanda.Program.Main() C:\Users\Circass\Documents\Visual Studio 2008\Projects\UzaktanKumanda\UzaktanKumanda\Program.cs içinde: satır 18

      konum: System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

      konum: System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

      konum: Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

      konum: System.Threading.ThreadHelper.ThreadStart_Context(Object state)

      konum: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

      konum: System.Threading.ThreadHelper.ThreadStart()


I m getting this error when i tried to send data to parallel port. What can be the problem, i searched it but couldnt find anything...

October 8, 2009 2:33 AM

sybaskan said:

Form1 2 3 4  etc   properties


December 12, 2010 8:48 PM

Patrick said:

I tried setting AutoValidate to disabled but it made no difference and did not fix my problem. I'm still getting the "System.Runtime.InteropServices.SEHException" problem as described above.  The way I attempted this fix is in my form constructor before the components are initialized/allocated:

this->AutoValidate = System::Windows::Forms::AutoValidate::Disable;

September 10, 2011 6:06 PM

Leave a Comment


Protected by FormShield
Please enter the characters shown on the image


Copyright ©2004-2007 Kevin Gearing. All Rights Reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems