C# 您应该如何诊断错误 SEHException - External component has throw an exception

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1313853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 15:01:07  来源:igfitidea点击:

How should you diagnose the error SEHException - External component has thrown an exception

c#winforms.net-2.0error-logging

提问by sgmoore

Whenever a user reports an error such as

每当用户报告错误时,例如

System.Runtime.InteropServices.SEHException- External component has thrown an exception?

System.Runtime.InteropServices.SEHException- 外部组件抛出异常?

is there anything that I as a programmer can do to determine the cause?

作为程序员,我可以做些什么来确定原因吗?

Scenario : One user (using a program my company wrote) has reported this error. This may or may not have been a one off error. They mentioned that in the last month, the computer has twice 'stopped working'. I have learnt from experience, not to take this description too literally, as it usually means that someone relating to the computer is not working as expected. They were unable to give me more details and I could not find any logged errors. Hence it may or may not have been this error.

场景:一位用户(使用我公司编写的程序)报告了此错误。这可能是也可能不是一次性错误。他们提到,在上个月,计算机曾两次“停止工作”。我从经验中吸取了教训,不要太字面理解这个描述,因为这通常意味着与计算机相关的某个人没有按预期工作。他们无法给我更多细节,我也找不到任何记录的错误。因此它可能是也可能不是这个错误。

From the stack-trace, the actual error was when constructing a class which does not directly call any interop code, but perhaps complicated by the fact that the object may be part of a list that is databound to a DevExpress Grid.

从堆栈跟踪来看,实际的错误是在构造一个不直接调用任何互操作代码的类时,但可能由于对象可能是数据绑定到 DevExpress 网格的列表的一部分而变得复杂。

The error was 'caught' by an unhandled exception routine which normally will close down the program, but has an option to ignore and continue. If they opted to ignore the error, then the program continued working but the error re-occurred when this routine was next run. However it did not occur again after closing and restarting our application.

该错误被未处理的异常例程“捕获”,该例程通常会关闭程序,但可以选择忽略并继续。如果他们选择忽略错误,则程序会继续运行,但下次运行此例程时错误会再次发生。但是,在关闭并重新启动我们的应用程序后,它没有再次发生。

The computer in question did not seem to be stressed out. It is running Vista Business, has 2GB of memory and according to Task Manager was only using about half of that with our application just about 200Mb.

有问题的计算机似乎没有压力。它运行的是 Vista Business,有 2GB 的内存,根据任务管理器的说法,它只使用了其中的一半,而我们的应用程序只有大约 200Mb。

There is one other piece of information that may or may not be relevant. Another section of the same program uses a third party component which is effectively a dotnet wrapper around a native dll and this component does have a known issue where very occasionally, you get a

还有另一条信息可能相关,也可能不相关。同一程序的另一部分使用第三方组件,该组件实际上是本机 dll 的 dotnet 包装器,并且该组件确实存在一个已知问题,偶尔会出现

Attempted to read or write protected memory. This is often an indication that other memory is corrupt

尝试读取或写入受保护的内存。这通常表明其他内存已损坏

The component makers say that this has been fixed in the latest version of their component which we are using in-house, but this has not been given to the customer yet.

组件制造商表示,这已在我们内部使用的最新版本的组件中修复,但尚未提供给客户。

Given that the consequences of the error are low (no work is lost and restarting the program and getting back to where they were only takes a minute at most) and given that the customer will shortly be getting a new version (with the updated third-party component), I can obviously cross my fingers and hope the error won't occur again.

考虑到错误的后果很低(没有工作丢失,重新启动程序并回到原来的位置最多只需要一分钟)并且考虑到客户很快就会得到一个新版本(更新后的第三个-派对组件),我显然可以交叉手指并希望错误不会再次发生。

But is there anything more I can do?

但我还能做些什么吗?

采纳答案by Reed Copsey

Yes. This error is a structured exception that wasn't mapped into a .NET error. It's probably your DataGrid mapping throwing a native exception that was uncaught.

是的。此错误是未映射到 .NET 错误的结构化异常。可能是您的 DataGrid 映射引发了未捕获的本机异常。

You can tell what exception is occurring by looking at the ExternalException.ErrorCodeproperty. I'd check your stack trace, and if it's tied to the DevExpress grid, report the problem to them.

您可以通过查看ExternalException.ErrorCode属性来判断发生了什么异常。我会检查您的堆栈跟踪,如果它与 DevExpress 网格相关联,请向他们报告问题。

回答by ChrisW

The component makers say that this has been fixed in the latest version of their component which we are using in-house, but this has been given to the customer yet.

组件制造商表示,这已在我们内部使用的最新版本的组件中得到修复,但尚未提供给客户。

Ask the component maker how to test whether the problem that the customer is getting is the problem which they say they've fixed in their latest version, without/before deploying their latest version to the customer.

询问组件制造商如何测试客户遇到的问题是否是他们声称已在最新版本中修复的问题,而没有/在向客户部署最新版本之前。

回答by Safran Ali

if you are having a problem as describe in this post:

如果您遇到本文中描述的问题:

asp.net mvc debugger throwing SEHException

asp.net mvc 调试器抛出 SEHException

then the solution is:

那么解决办法是:

if you have any application from Trusteer (like rapport or anything ) just uninstall and reboot your system, it'll work fine ... found this solution here:

如果您有来自 Trusteer 的任何应用程序(如 rapport 或任何东西),只需卸载并重新启动您的系统,它就可以正常工作......在这里找到了这个解决方案:

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

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

回答by Maurice Gilden

I had a similar problem with an SEHException that was thrown when my program first used a native dll wrapper. Turned out that the native DLL for that wrapper was missing. The exception was in no way helpful in solving this. What did help in the end was running procmon in the background and checking if there were any errors when loading all the necessary DLLs.

当我的程序第一次使用本机 dll 包装器时,我遇到了类似的 SEHException 问题。结果发现该包装器的本机 DLL 丢失了。异常对解决这个问题没有任何帮助。最后有什么帮助是在后台运行 procmon 并检查在加载所有必要的 DLL 时是否有任何错误。

回答by Conrad

I have come across this error when the app resides on a network share, and the device (laptop, tablet, ...) becomes disconnected from the network while the app is in use. In my case, it was due to a Surface tablet going out of wireless range. No problems after installing a better WAP.

当应用程序驻留在网络共享上时,我遇到了此错误,并且在使用应用程序时设备(笔记本电脑、平板电脑等)与网络断开连接。就我而言,这是由于 Surface 平板电脑超出了无线范围。安装更好的 WAP 后没有问题。

回答by Conrad

Just another information... Had that problem today on a Windows 2012 R2 x64 TS system where the application was started from a unc/network path. The issue occured for one application for all terminal server users. Executing the application locally worked without problems. After a reboot it started working again - the SEHException's thrown had been Constructor init and TargetInvocationException

只是另一个信息......今天在 Windows 2012 R2 x64 TS 系统上遇到了这个问题,其中应用程序是从 unc/network 路径启动的。对于所有终端服务器用户的一个应用程序发生了该问题。在本地执行应用程序没有问题。重新启动后,它再次开始工作 - 抛出的 SEHException 是 Constructor init 和 TargetInvocationException

回答by RBT

My machine configurations :

我的机器配置:

Operating System : Windows 10 Version 1703 (x64)

操作系统:Windows 10 版本 1703 (x64)

I faced this error while debugging my C# .Net project in Visual Studio 2017 Community edition. I was calling a native method by performing p/invoke on a C++ assembly loaded at run-time. I encountered the very same error reported by OP.

我在 Visual Studio 2017 社区版中调试我的 C# .Net 项目时遇到了这个错误。我通过在运行时加载的 C++ 程序集上执行 p/invoke 来调用本机方法。我遇到了 OP 报告的完全相同的错误。

I realized that Visual Studio was launched with a user account which was not an administrator on the machine. Then I relaunched Visual Studio under a different user account which was an administrator on the machine. That's all. My problem got resolved and I didn't face the issue again.

我意识到 Visual Studio 是使用不是机器管理员的用户帐户启动的。然后我在另一个用户帐户下重新启动了 Visual Studio,该用户帐户是机器上的管理员。就这样。我的问题得到了解决,我没有再遇到这个问题。

One thing to note is that the method which was being invoked on C++ assembly was supposed to write few things in registry. I didn't go debugging the C++ code to do some RCA but I see a possibility that the whole thing was failing as administrative privileges are required to write registry in Windows 10 operating system. So earlier when Visual Studio was running under a user account which didn't have administrative privileges on the machine, then the native calls were failing.

需要注意的一件事是,在 C++ 程序集上调用的方法应该在注册表中写入很少的内容。我没有去调试 C++ 代码来做一些 RCA,但我看到整个事情失败的可能性,因为在 Windows 10 操作系统中写入注册表需要管理权限。所以早些时候,当 Visual Studio 在没有机器管理权限的用户帐户下运行时,本机调用失败了。

回答by atreyHazelHispanic

I got this error while running unit tests on inmemory caching I was setting up. It flooded the cache. After invalidating the cache and restarting the VM, it worked fine.

在我正在设置的内存缓存上运行单元测试时出现此错误。它淹没了缓存。使缓存无效并重新启动虚拟机后,它工作正常。