gpt4 book ai didi

.net - 常见原因 - .NET 下的访问冲突错误

转载 作者:行者123 更新时间:2023-12-04 12:38:40 25 4
gpt4 key购买 nike

我正在寻找 .NET 下访问冲突错误的常见原因。

到目前为止我检查过的东西 -

  • 在所有实现 IDisposable 的对象上调用 Dispose
  • 检查对 COM 对象的调用中的有效参数
  • 显式删除所有手动添加的事件处理程序
  • 不要显式调用 GC.Collect/GC.WaitForPendingFinalizers
  • 添加和消除处理 native 对象(位图等)时的内存压力( 添加 )
  • 验证有效参数类型的所有 PInvoke 调用
  • 确保正确使用 IntPtr、SafeHandle 和 HandleRef
  • 线程(线程安全,可重入函数),正确使用等待句柄。 ( 添加 )
  • 确保应用程序和 DLL 都针对相同的平台(x86 或 x64)(应用程序和 dll 应该针对与 COM 对象相同的平台。)( 添加 )

  • 还有其他建议吗?

    编辑 - 将故障转储分析移至不同的问题。

    最佳答案

    任何不安全或非托管代码的使用都可能导致此类异常。

    AccessViolationException:

    An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been allocated, or to which it does not have access. This usually occurs because a pointer has a bad value. Not all reads or writes through bad pointers lead to access violations, so an access violation usually indicates that several reads or writes have occurred through bad pointers, and that memory might be corrupted. Thus, access violations almost always indicate serious programming errors. In the .NET Framework version 2.0, an AccessViolationException clearly identifies these serious errors.

    In programs consisting entirely of verifiable managed code, all references are either valid or null, and access violations are impossible. An AccessViolationException occurs only when verifiable managed code interacts with unmanaged code or with unsafe managed code.



    受到推崇的:

    GFlagsApplication Verifier

    关于.net - 常见原因 - .NET 下的访问冲突错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/526649/

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