Ankush Madankar
Ankush Madankar

Reputation: 3834

Accessviolationexception attempted to read or write protected memory

I create one Windows Form App on my friends machine. It works fine on his machine. But when I tried to run same App on my own machine then from _dialog.ShowDialog() line an exception thrown like "accessviolationexception attempted to read or write protected memory. this is often an indication that other memory is corrupt...". I check for this error on net and I found following solutions:

1) Tools menu ->Options -> Debugging -> General -> Uncheck this option "Suppress JIT optimization on module load" link : 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. Done on my machine but wasnt work.

2) Attempted to read or write protected memory, Install http://support.microsoft.com/kb/971030 for framework 2.0,..3.5, but I dont find any of download product from mention link.

My machine configuration: VS 2010(SP1), Framework used 4.0, DB used MS-Access.

Block of code:

    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?;
        }
    }

Any useful help?

Upvotes: 1

Views: 661

Answers (1)

Sunder
Sunder

Reputation: 169

Turning off the DEP settings may solve your problem. Turn off DEP via an elevated Command Prompt by clicking the Windows (Start) > All Programs > Accessories and right-click Command Prompt, then ‘Run as Administrator’. Type bcdedit.exe /set {current} nx AlwaysOff (note the four spaces) and press Enter. To turn it back on, change AlwaysOff to AlwaysOn. You need to restart the system after the changes have been made.

Upvotes: 1

Related Questions