不能赶上0000005例外,在C# [英] Can't catch 0xC0000005 exception in C#

查看:354
本文介绍了不能赶上0000005例外,在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到在我的C#.NET程序以下异常:

I am getting the following exception in my C#.Net program:

有一个第一次机会异常类型'System.Data.SqlClient.SqlException'在System.Data.dll中发生   在0x000007feff75121b第一次机会异常的程序myapp.exe:0000005:访问冲突读取位置0x0000000000000000。   第一个机会异常类型的System.AccessViolationException在CustomMarshalers.dll发生   类型的未处理的异常'System.AccessViolationException在CustomMarshalers.dll发生   其他信息:试图读取或写入受保护的内存。这通常表明其他内存已损坏。

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll First-chance exception at 0x000007feff75121b in myapp.exe: 0xC0000005: Access violation reading location 0x0000000000000000. A first chance exception of type 'System.AccessViolationException' occurred in CustomMarshalers.dll An unhandled exception of type 'System.AccessViolationException' occurred in CustomMarshalers.dll Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

我明白了一个try / catch(异常)块内,但它永远不会被抓住。

I get it inside of a try/catch(Exception) block but it is never being caught.

我试图对其进行调试,看看它为什么发生,但它是很难做到的,没有赶上它。

I'm trying to debug it to see why it is happening but it is difficult to do that without catching it.

应该可以赶上0000005异常C#.NET? (框架4.0在Windows 2008 R2)。

Should it be possible to catch a 0xC0000005 exception in C#.Net? (Framework 4.0 on Windows 2008 R2).

感谢您的任何提示。

推荐答案

您无法在默认情况下捕获一个AccessViolationException,因为它表明一个尝试读取或写入受保护的内存。您可以添加的<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.exceptionservices.handleprocesscorruptedstateexceptionsattribute.aspx"><$c$c>[HandleProcessCorruptedStateExceptions]属性的方法,其中这样的情况,虽然:

You cannot catch an AccessViolationException by default, as it indicates a try to read or write protected memory. You can add the [HandleProcessCorruptedStateExceptions] attribute to the method where it occurs, though:

在默认情况下,公共语言运行库(CLR)不提供这些例外管理code,并在尝试 / *的的*块(和其他异常处理条款)不为他们调用。如果你是绝对相信,你要保持你的这些例外的处理,必须应用在 HandleProcessCorruptedStateExceptionsAttribute 属性要执行的异常处理条款的方法。在CLR只有在同时拥有 HandleProcessCorruptedStateExceptionsAttribute 和<一个方法提供了损坏的进程状态例外适用的例外条款href="http://msdn.microsoft.com/en-us/library/system.security.securitycriticalattribute.aspx">SecurityCriticalAttribute属性。

By default, the common language runtime (CLR) does not deliver these exceptions to managed code, and the try/*catch* blocks (and other exception-handling clauses) are not invoked for them. If you are absolutely sure that you want to maintain your handling of these exceptions, you must apply the HandleProcessCorruptedStateExceptionsAttribute attribute to the method whose exception-handling clauses you want to execute. The CLR delivers the corrupted process state exception to applicable exception clauses only in methods that have both the HandleProcessCorruptedStateExceptionsAttribute and SecurityCriticalAttribute attributes.

这篇关于不能赶上0000005例外,在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆