我在我的朋友機器上創建一個Windows窗體應用程序。它在他的機器上正常工作。但是當我試圖在自己的機器上運行相同的應用程序時,則從_dialog.ShowDialog()
行中會拋出一個異常,如「accessviolationexception嘗試讀取或寫入受保護的內存,這通常表示其他內存已損壞......」。我檢查網絡上的這個錯誤,我發現了以下解決方案: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爲框架2.0,.. 3.5,但我沒有找到任何從提到鏈接的下載產品。
我的機器配置:VS 2010(SP1),Framework使用4.0,數據庫使用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?;
}
}
任何有益的幫助?