【问题标题】:Accessviolationexception attempted to read or write protected memory访问冲突异常试图读取或写入受保护的内存
【发布时间】:2013-08-05 18:41:54
【问题描述】:

我在朋友的机器上创建了一个 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,为框架 2.0,..3.5 安装 http://support.microsoft.com/kb/971030,但我没有从提及的链接中找到任何下载产品。

我的机器配置: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?;
        }
    }

有什么有用的帮助吗?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-19
      • 1970-01-01
      • 2014-08-07
      • 2011-01-08
      • 2012-09-21
      • 2012-04-16
      • 2020-07-14
      • 1970-01-01
      相关资源
      最近更新 更多