I'm using Win7 with Visual Studio 2013
My Application is a webbrowser-component with GeckoFx. At the download-call I trigger to open the SaveFileDialog. On some cases (not on every call) I got the following error, when I call SaveFileDialog in line 822 (see also code below):
System.AccessViolationException wurde nicht behandelt.
HResult=-2147467261
Message=Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf, dass anderer Speicher beschädigt ist.
Source=System.Windows.Forms
StackTrace:
bei System.Windows.Forms.UnsafeNativeMethods.GetSaveFileName(OPENFILENAME_I ofn)
bei System.Windows.Forms.SaveFileDialog.RunFileDialog(OPENFILENAME_I ofn)
bei System.Windows.Forms.FileDialog.RunDialogOld(IntPtr hWndOwner)
bei System.Windows.Forms.FileDialog.RunDialog(IntPtr hWndOwner)
bei System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
bei System.Windows.Forms.CommonDialog.ShowDialog()
bei MYAPPLICATION.modMain.LauncherDialog_Download(Object sender, LauncherDialogEvent e) in X:\COMPANY\products\APPLICATIONWITHGecko45\MYAPPLICATION\modMain.vb:Zeile 822.
bei Gecko.LauncherDialog.Show(nsIHelperAppLauncher aLauncher, nsISupports aWindowContext, UInt32 aReason) in D:\temp\9f0c5cd\Geckofx-Winforms\Dialogs\GeckoHelperAppLauncherDialog.cs:Zeile 91.
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(ApplicationContext context)
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bei MYAPPLICATION.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.
InnerException:
I already searched for this problem and took care of saveFileDialog1.AutoUpgradeEnabled = False as many solutions suggests, but it didn't help.
Here are the lines in which the error appears. Note: I had to call the SaveFileDialog in some cases twice.. I don't know why this happens. I just asked another question for why this happens (see here SaveFileDialog closes automatically directly after calling showDialog())
Public Sub LauncherDialog_Download(ByVal sender As Object, ByVal e As Gecko.LauncherDialogEvent)
Try
Dim P As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & Path.DirectorySeparatorChar & "tmp" 'globalParameters._downloadDirectory '
If Not System.IO.Directory.Exists(P) Then System.IO.Directory.CreateDirectory(P)
Dim objTarget As nsILocalFile = Xpcom.CreateInstance(Of nsILocalFile)("@mozilla.org/file/local;1")
Using tmp As New nsAString(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + vbTab & "temp.tmp")
objTarget.InitWithPath(tmp)
End Using
'Save file dialog
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "CSV file (*.csv)|*.csv|All files (*.*)|*.*"
saveFileDialog1.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True
saveFileDialog1.FileName = e.Filename
saveFileDialog1.AutoUpgradeEnabled = False
saveFileDialog1.CheckPathExists = False
saveFileDialog1.InitialDirectory = globalParameters.getDownloadDirectory() 'globalParameters._downloadDirectory
If globalParameters._doNotShowDownloadPrompt Then
' this code Part does not happen in my cases and we can ignore it
Else
Dim dialogResultValue As DialogResult
Try
dialogResultValue = saveFileDialog1.ShowDialog()
Catch ex As Exception
logging.logInformation("Problems during loading of dialog: " & ex.ToString())
End Try
' SpecialCase, if CSV File or Dicom just reopen dialog
' crazy but helps to display dialog
logging.logInformation("Download URL: " & e.Url)
If (e.Url.Contains("format=CSV") Or e.Url.Contains("DocGenericZIP") Or e.Url.Contains("type=application/dicom")) And dialogResultValue = DialogResult.Cancel Then
Try
saveFileDialog1.Dispose() ' dispose old saveFileDialog
saveFileDialog1 = New SaveFileDialog()
saveFileDialog1.Filter = "CSV file (*.csv)|*.csv|All files (*.*)|*.*"
saveFileDialog1.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True
saveFileDialog1.FileName = e.Filename
saveFileDialog1.AutoUpgradeEnabled = False
saveFileDialog1.InitialDirectory = globalParameters.getDownloadDirectory()
saveFileDialog1.CheckPathExists = False
dialogResultValue = saveFileDialog1.ShowDialog() 'this is the line 822 mentioned in the error above
Catch ex As Exception
logging.logInformation("Errors during loading of fole Dialog: " & ex.ToString())
End Try
End If
' if upper saveFileDialog runs without errors, following lines works like a charm
If dialogResultValue = DialogResult.OK Then
Try
' these lines put the download Information into another thread, so that the download
' can run and the user can use the browser simultaneously,
' otherwise the interaction in main-Form is blocked
Dim par As New Parameters
par.sender = sender
par.e = e
par.mime = e.Mime
par.url = e.Url
par.fileName = saveFileDialog1.FileName
par.dialogResultValue = dialogResultValue
par.myStream = saveFileDialog1.OpenFile()
ThreadJob(par)
Catch ex As Exception
logging.logInformation("Error during loading of File" & e.ToString)
End Try
End If
End If
Catch ex As Exception
logging.logInformation("Error during loading file. " & ex.ToString, "main", True)
Finally
'nothing to do here
End Try
End Sub