gpt4 book ai didi

c# - 无法在 C# 中捕获 0xC0000005 异常

转载 作者:行者123 更新时间:2023-11-30 19:45:11 30 4
gpt4 key购买 nike

我的 C#.Net 程序出现以下异常:

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(Exception) block 中获取它,但它从未被捕获。

我正在尝试调试它以了解它发生的原因,但如果不捕获它就很难做到这一点。

是否可以在 C#.Net 中捕获 0xC0000005 异常? (Windows 2008 R2 上的框架 4.0)。

感谢任何提示。

最佳答案

默认情况下您无法捕获 AccessViolationException,因为它表示尝试读取或写入 protected 内存。您可以添加 [HandleProcessCorruptedStateExceptions]属性到它发生的方法,但是:

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.

关于c# - 无法在 C# 中捕获 0xC0000005 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11056080/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com