c# - 程序随机获取 System.AccessViolationException

标签 c# debugging runtime-error

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

An unhandled exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

这也不是我代码的错。我做了一个简单的测试作为下面的例子。请注意,我没有从该应用中引用 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();
            }
        }
    }

我不知道是什么原因造成的。如果我单击确定并再次运行它,大多数情况下它会起作用。有时我必须做两次。

有什么想法吗?

堆栈跟踪:

enter image description here

最佳答案

将平台目标更改为 x86 对我有用,如果没有上述异常,单步执行代码是不可能的。我运行 Win 8.1 64 位和 Visual Studio 2013。

关于c# - 程序随机获取 System.AccessViolationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24294543/

相关文章:

c - 为什么这段代码会给出运行时错误?

c# - 防止 Visual Studio 在多行注释中输入时添加额外的星号

c# - 使用 Moq 模拟存储库

javascript - firebug 不断停止执行脚本

c# - 如何在 Visual Studio 中测试运行需要 SSL 的 ASP.NET MVC 网站?

c++ - 使用 cv::addWeighted 时出错

c# - 如何使用反射确定基类的泛型参数

c# - 是否应为同一实体创建多个数据契约(Contract)

json - 在“网络”标签中仅显示JSON调用

android - Xamarin Android Theme.AppCompat 错误 - 仅在运行时