【问题标题】:SEHException was unhandledSEHException 未处理
【发布时间】:2011-10-18 02:19:22
【问题描述】:

我有一个昨天运行良好的 vs2010 c# 解决方案。

当我今天尝试运行调试实例时,我不断收到 SEHException 未处理。

在启动表单的InitializeComponent 方法中抛出此错误。

有什么想法吗?

这是堆栈跟踪:

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: 

我的女朋友昨晚把我的笔记本电脑屏幕弄坏了,所以我在外接显示器上运行......这与它有什么关系吗?

这是代码和错误的行..

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";
}

【问题讨论】:

  • 我非常怀疑你另一半的恶作剧与这个例外有什么关系:)
  • 值得一试 moo :) 因为看起来异常与自动缩放有关,所以我想知道显示器的不同分辨率是否与它有关
  • 查看我的帖子并在此处回答:stackoverflow.com/questions/6910029/…
  • 我最近在实例化一个非常简单的对象时开始收到此错误。虽然我从来没有设法找出原因,但在管理员模式下运行 Visual Studio 后,问题就消失了。对于任何通过谷歌搜索登陆这里的人来说可能值得一试:)

标签: c# .net visual-studio-2010


【解决方案1】:

这可能与昨天开始发生的广泛报道的问题相同。见

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

如果您的计算机上有“Trusteer Rapport”,请尝试卸载它

【讨论】:

  • 很好的诊断。我认为像这样的答案的问题是 SO 的真正瑰宝 :)
  • 我不能真正声称任何功劳——我只是在关注这个问题上的其他线程,因为我的一位同事正在遭受这个问题的困扰。它只是显示了当不相关的软件会以这种意想不到的方式相互影响时,Windows 环境是多么敏感。
【解决方案2】:

说实话,zeroid 的回答并没有解决我的问题。所以为了完整起见,我想补充一点,avira也引起了这样的问题

【讨论】:

    【解决方案3】:

    当您在主线程中加载非托管函数(从 DLL)时,可能会出现此问题。 我通过在与主线程不同的线程中加载这些非托管函数来解决此问题,例如,您可以使用BackgroundWorker

    【讨论】:

      【解决方案4】:

      我偶然发现了这一点,因为我突然遇到了同样的问题。这是OP之后的几年,我正在使用VS2015。我的解决方案昨天在工作中运行良好,我的笔记本电脑连接到了外接显示器。今天我在家工作,没有额外的显示器。除了 OP 关于切换屏幕设置的评论之外,我不会认为它相关。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多