程序随机获取System.AccessViolationException

Fro*_*ire 12 c# debugging runtime-error

好的,所以我在调试时遇到了很多问题.我正在使用VS2013 Pro和Windows 8.1.两者都是最新的.问题是,当我开始调试时,它会抛出此错误的一半时间:

System.Windows.Forms.dll中发生了未处理的"System.AccessViolationException"类型异常

附加信息:尝试读取或写入受保护的内存.这通常表明其他内存已损坏.

它也不是我的代码的错.我做了一个简单的测试作为例子如下.请注意,我没有从此应用程序引用System.Windows.Forms.

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

    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<int> testing = new List<int>();
                for(int i =0; i < 50; i++)
                {
                    testing.Add(i);
                }

                for (int i = 0; i < 50; i++)
                {
                    Console.WriteLine(testing[i].ToString());

                }

                Console.ReadLine();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我不知道是什么造成了这个.如果我单击"确定"并再次运行它,它将起作用.偶尔我必须做两次.

有任何想法吗?

堆栈跟踪:

在此输入图像描述

Nul*_*ull 8

将平台目标更改为x86对我来说是有用的,如果没有前面提到的异常,就不可能单步执行代码.我运行Win 8.1 64位和Visual Studio 2013.


小智 6

我也使用visual studio express2015在windows10上遇到了这个问题.构建到x86并没有解决我的问题,但以下解决方法做了诀窍:

此问题是由收集返回值的代码引起的.可以通过禁用托管返回值来解决此问题.

  1. 转到系统属性(Win8:WinKey + X,选择'系统',Win7:从我的计算机打开'属性')
  2. 高级系统设置
  3. 环境变量…
  4. 点击"新建"并添加
    • 名称:VSDebug_DisableManagedReturnValue
    • 价值:1

来源:https://connect.microsoft.com/VisualStudio/feedback/details/819552/visual-studio-debugger-throws-accessviolationexception