15

I have a vs2010 c# solution that was working fine yesterday.

When I try and run a debug instance today I keep getting an SEHException was unhandled.

This error is being thrown in the InitializeComponent method of the startup form.

Any Ideas?

Here's the stacktrace:

System.Runtime.InteropServices.SEHException was unhandled
  Message=External component has thrown an exception.
  Source=System.Drawing
  ErrorCode=-2147467259
  StackTrace:
       at System.Drawing.SafeNativeMethods.Gdip.GdipCreateFontFromLogfontW(HandleRef hdc, Object lf, IntPtr& font)
       at System.Drawing.Font.FromLogFont(Object lf, IntPtr hdc)
       at System.Drawing.Font.FromHfont(IntPtr hfont)
       at System.Drawing.SystemFonts.get_DefaultFont()
       at System.Windows.Forms.Control.get_DefaultFont()
       at System.Windows.Forms.Control.GetDefaultFontHandleWrapper()
       at System.Windows.Forms.Control.get_FontHandle()
       at System.Windows.Forms.ContainerControl.GetFontAutoScaleDimensions()
       at System.Windows.Forms.ContainerControl.get_CurrentAutoScaleDimensions()
       at System.Windows.Forms.ContainerControl.get_AutoScaleFactor()
       at System.Windows.Forms.ContainerControl.PerformAutoScale(Boolean includedBounds, Boolean excludedBounds)
       at System.Windows.Forms.ContainerControl.PerformNeededAutoScaleOnLayout()
       at System.Windows.Forms.Form.OnLayout(LayoutEventArgs levent)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
       at System.Windows.Forms.ContainerControl.LayoutScalingNeeded()
       at System.Windows.Forms.ContainerControl.set_AutoScaleMode(AutoScaleMode value)
       at FirstWindow.Form1.InitializeComponent() in C:\Users\Ash\Documents\Visual Studio 2010\Projects\FrameworkClientV2 - No Security\FirstWindow\Form1.designer.cs:line 32
       at FirstWindow.Form1..ctor() in C:\Users\Ash\Documents\Visual Studio 2010\Projects\FrameworkClientV2 - No Security\FirstWindow\Form1.cs:line 27
       at FirstWindow.Program.Main() in C:\Users\Ash\Documents\Visual Studio 2010\Projects\FrameworkClientV2 - No Security\FirstWindow\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

On a random note my gf broke my laptop screen last night so Im running on an external monitor... could this have anything to do with it?

Here's the code and the erroneous line..

private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    ///////////////////The line below throws the exception
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    /////////////////////////////// 
    this.Text = "Form1";
}
akjoshi
  • 15,374
  • 13
  • 103
  • 121
user589195
  • 4,180
  • 13
  • 53
  • 81
  • possible duplicate of [How should you diagnose the error SEHException - External component has thrown an exception](http://stackoverflow.com/questions/1313853/how-should-you-diagnose-the-error-sehexception-external-component-has-thrown-an) – Cody Gray - on strike Aug 02 '11 at 09:29
  • 5
    I very much doubt the shenanigans of your better half have anything to do with this exception :) – Moo-Juice Aug 02 '11 at 09:31
  • It was worth a try moo :) Since it looks like the exception is something to do with Autoscaling I wondered if the defferent resolutions of the monitors might have something to do with it – user589195 Aug 02 '11 at 09:50
  • 1
    For the answer checkout my post and answer here : http://stackoverflow.com/questions/6910029/asp-net-mvc-debugger-throwing-sehexception – Safran Ali Aug 24 '11 at 23:10
  • I recently started receiving this error when instantiating a pretty simple object. Although I never did manage to figure out the cause, after running Visual Studio in administrator mode, the problem disappeared. Might be worth a try for anyone who lands here via a google search :) – redspidermkv Nov 21 '14 at 12:37

4 Answers4

12

This might be the same as the widely reported issue that started occurring yesterday. See

http://forums.asp.net/t/1704958.aspx/9/10?Re+SEHException+thrown+when+I+run+the+application

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/0f78401b-77b2-4052-a26a-e98d2ec0afa9

Try uninstalling "Trusteer Rapport" if you have it on your machine

zeroid
  • 701
  • 7
  • 19
  • 3
    Great diagnosis. I think questions with answers like this one are the true gems of SO :) – porges Aug 02 '11 at 10:56
  • 5
    I can't really claim any credit - I was just following the other threads on this issue as a colleague of mine was suffering this issue. It just shows how sensitive the Windows environment is when unrelated software can affect each other in unexpected ways like this. – zeroid Aug 02 '11 at 11:06
1

To be honest, the answer by zeroid did not fix my problem. So for the sake of completeness, I'd like to add that avira also caused such problems

ingkebil
  • 132
  • 6
0

This problem can occurs when you load unmanaged functions (from DLL) in the main thread. I fixed this problem by loading these unmanaged functions in a different thread than the main thread, you can for example use a BackgroundWorker.

quent
  • 1,936
  • 1
  • 23
  • 28
0

I stumbled on this because I suddenly experienced the same problem. It's years after the OP and I'm using VS2015. My solution worked fine at work yesterday, with my laptop hooked up to an an external monitor. Today I'm working from home, and there is no extra monitor. I wouldn't have thought it relevant except for OP's comment about switching screen setup.

mhvelplund
  • 2,099
  • 3
  • 22
  • 38