我真的很感謝你的幫助。我的應用如下,在VB.Net(VS 2012)中打開「OpenFileDialog」時發生異常「System.AccessViolationException」
作業系統:Windows 7 64位操作系統
的Visual Studio:VS 2012
應用:VB.Net上的.Net Framework 4的
運行在我的應用程序,我有一個按鈕它調用我的自定義方法'Select_Batch_File()'。一旦這個按鈕被點擊,它假設打開'OpenFileDialog'來選擇特定的文件。然而,在我的機器上使用上述配置可以正常工作;在我的一些同事機器上(具有上述相同配置),這不起作用,並且沒有任何異常而失敗。我收集了從我的同事的機器,如下所示,
======================
日誌名稱的線程轉儲:應用
來源:.NET運行庫
日期:2013年3月18日下午1點54分19秒
事件ID:1026
任務類別:無
級別:錯誤
關鍵字:經典
用戶:N/A
描述:
應用:視覺AEEMS.exe
Framework版本:v4.0.30319
描述:由於未處理的異常而終止進程。
異常的信息:System.AccessViolationException
堆棧:
在System.Windows.Forms.FileDialogNative + IFileDialog.Show(IntPtr的)
在System.Windows.Forms.FileDialog.RunDialogVista(的IntPtr)
在System.Windows.Forms.FileDialog.RunDialog(IntPtr的)
在System.Windows.Forms.CommonDialog .ShowDialog(System.Windows.Forms.IWin32Window)
===============
我跟着從MSDN論壇的解決方案,其中用戶被要求取消對中visual studio>工具>選項>調試>'禁止模塊負載JIT優化(只管理)',但沒有運氣。
這裏是我的代碼
Sub Select_Batch_File()
Try
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.AutoUpgradeEnabled = False
Full_Path = "" : file_name = ""
OpenFileDialog.Multiselect = False
Try
<<Here I am getting exception>>
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
EMS_Dir = OpenFileDialog.FileName 'get the path
EMS_Dir = StrReverse(EMS_Dir) 'reverse the string
EMS_Dir = Mid(EMS_Dir, InStr(EMS_Dir, "\"), Len(EMS_Dir)) 'extract from the first slash
EMS_Dir = StrReverse(EMS_Dir) 'reverse it again
'file_name = OpenFileDialog.SafeFileName
file_name = OpenFileDialog.FileName
End If
Catch ex As Exception
Logger.LogInfo(ex) : MsgBox(ex.Message)
End Try
Catch ex As Exception
Logger.LogInfo(ex) : MsgBox(ex.Message)
End Try
End Sub
請指點。
它可能沒有幫助的問題 - 但你應該*絕對*熟悉System.IO命名空間 - 尤其是System.IO.Path類。 – 2013-03-19 07:05:13