相关疑难解决方法(0)

奇怪的访问冲突异常

我很困惑AccessViolationException.这是相当IM可能(请参阅回答)有一个干净的再现,但在这里不用的总体思路:

class MyClass 
{
  public List<SomeType> MyMethod(List<string> arg)
  {
     // BREAKPOINT here
     // Simple stuff here, nothing fancy, no external libs used
  }
}

delegate List<SomeType> MyDelegate(List<string> arg);

... 

var myObject = new MyClass();

Func<List<string>, List<SomeType>> myFunc = myObject.MyMethod;
MyDelegate myDelegate = myObject.MyMethod;

myFunc(null)            // works fine
myDelegate(null)        // works fine
myObject.MyMethod(null) // throws AccessViolationException
Run Code Online (Sandbox Code Playgroud)

奇怪的是我没有使用任何不安全的代码.我对任何地方(以及整个程序执行AFAIK中的任何地方)的外部库都没有任何依赖关系.

最奇怪的部分是这是100%可重复的,甚至在稍微重构代码之后,将方法调用移到别处,在它之前放置额外的代码等等 - 在所有情况下AccessViolationException仍然抛出特定的方法调用.直接调用时不会输入该方法(未点击断点).通过委托调用它或Func<>工作正常.

关于什么可能导致它或如何调试它的任何线索?

UPDATE

在antiduh的问题之后:在任何地方都没有从构造函数调用虚方法.发生这种情况时的实际堆栈跟踪非常简单,只需要两个静态方法和一个简单实例.

唯一的线索似乎是线程.在程序执行(而不是在调用堆栈中)之前Parallel.ForEach()之前都会Thread.Sleep()调用它.关于错误处理线程(使用常规托管类)如何导致AVE的任何线索? …

.net c# multithreading access-violation

14
推荐指数
1
解决办法
2261
查看次数

在Visual Studio 2013 Update 2中单步执行C#-Code时出现AccessViolationException

我想我在Visual Studio 2013 Update 2的调试器中发现了一个错误.当我从一个抽象类派生并覆盖一个接受带有两个字符串的结构的抽象方法时,调试会话崩溃并发生AccessViolationException.

此行为在64位体系结构和.NET Framework 4.0及更高版本(4.5和4.5.1)上出现.

重现步骤:

  1. 创建一个新的控制台项目.使用任何CPU或x64(这只适用于支持64位的系统!)并使用.NET Framework 4.0,4.5或4.5.1.
  2. 复制并粘贴以下代码.
  3. 在Main方法的第一行代码上设置断点.
  4. 逐步完成代码直到结束.
  5. AccessViolationException在Main方法的最后一行出现.

现在我的问题:

  1. 任何人都可以重现这种行为吗?
  2. 怎么会发生这种情况,我怎样才能比使用visual studio更好地调试这些错误?
  3. 我在哪里可以报告这种错误?

感谢您的时间.

码:

using System;
using System.Collections.Generic;
using System.Text;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            Structure structure = new Structure();

            Caller caller = new Caller();

            caller.Execute(structure);
        }
    }

    public abstract class Father
    {
        internal Father()
        {
        }

        public abstract bool Execute(Structure structure);
    }

    public class Caller : Father
    {
        public Caller() : base()
        {
        } …
Run Code Online (Sandbox Code Playgroud)

.net c# access-violation visual-studio-2013

11
推荐指数
0
解决办法
315
查看次数