Accessviolationexception尝试读取或写入受保护的内存

时间:2013-08-05 06:20:20

标签: c# c#-4.0 ms-access

我在朋友计算机上创建了一个Windows窗体应用程序。它在他的机器上工作正常。但是当我尝试在我自己的机器上运行相同的应用程序时,从_dialog.ShowDialog()行抛出一个异常,例如“accessviolationexception试图读取或写入受保护的内存。这通常表明其他内存已损坏......”。我在网上检查这个错误,我找到了以下解决方案:

1)工具菜单 - >选项 - >调试 - >一般 - >取消选中此选项“抑制模块加载时的JIT优化”链接:http://social.msdn.microsoft.com/Forums/en-US/8789ea67-fbc5-4a7b-a4eb-d4a8a050d5c1/attempt-to-read-or-write-protected-memory-this-is-often-an-indicating-that-other-memory-is-corrupt。在我的机器上完成但是没有工作。

2)Attempted to read or write protected memory,安装http://support.microsoft.com/kb/971030 for framework 2.0,.. 3.5,但我没有找到任何来自提及链接的下载产品。

我的机器配置:VS 2010(SP1),Framework使用4.0,DB使用MS-Access。

代码块:

    private void SetAttachmentInfo()
    {
        Dictionary<string, object> _fileInfo = new Dictionary<string, object>();
        OpenFileDialog _dialog = new OpenFileDialog();

        var _fileName = (object)(null);
        var _fileData = (object)(null);
        var _fileDataLength = (object)(null);

        _dialog.Multiselect = false;
        _dialog.Filter = "Office Files (*.doc;*.xls;*.ppt;*pdf;*txt) |*.doc;*xlsx;*.xls*.ppt;*pdf;*.txt;|Image Files (*.jpeg;*.png;*.jpg;*.gif) |*.jpeg;*.png;*.jpg;*.gif |All File|*.*";

        if (_dialog.ShowDialog() != DialogResult.Cancel)
        {
            _fileInfo = GetAttachmentFileInformation(_dialog.FileName);
            _fileInfo.TryGetValue("FileName", out _fileName);
            _fileInfo.TryGetValue("FileData", out _fileData);
            _fileInfo.TryGetValue("Lenght", out _fileDataLength);
            FileName = Convert.ToString(_fileName);
            FileData = (_fileData != null && (_fileDataLength as int?) > 0) ? (byte[])_fileData : (byte[])null;
            AttachmentLength = _fileDataLength as int?;
        }
    }

任何有用的帮助?

1 个答案:

答案 0 :(得分:1)

关闭DEP设置可能会解决您的问题。单击Windows(开始)&gt;通过提升的命令提示符关闭DEP。所有程序&gt;附件并右键单击“命令提示符”,然后“以管理员身份运行”。键入bcdedit.exe / set {current} nx AlwaysOff(注意四个空格),然后按Enter键。要重新打开它,请将AlwaysOff更改为AlwaysOn。您需要在完成更改后重新启动系统。