MDI application error with openFileDialog
-
Wednesday, November 03, 2010 12:39 AM
This is my first MDI application.
Error is when I am calling openFileDialog.showDialog(this) this call is then throwing AccessViolationException or System.Runtime.InteropServices.SEHException
I then read that a MDI child should not call a modaldialog such as openfiledialog (If I am wrong please let me know). So I then moved the code to the MDI parent and call the code from the child and I still get the error. The error is thrown about 80% of the time and I have to have at least 2 open MDI children. (So a total of 3 forms)
My goal is to have a child form prompt a user for a image file and then save the path. As this is my first MDI app and I use the openFileDialog all the time I am assuming there is a concept I am missing regarding MDI apps.
I guess I can paste the code but I sure you will need more. Any help would be appreciated. I have called this code from both the MDI parent and MDI child as stated above.
OpenFileDialog openFileDialog2 = new OpenFileDialog(); DialogResult dr; try { dr = openFileDialog2.ShowDialog(); } catch (AccessViolationException ex) { throw ex; } catch (Exception ex) { MessageBox.Show(ex.Message); throw ex; }
All Replies
-
Wednesday, November 03, 2010 1:32 AM
Showing a modal dialog is usually fine from an MDI child window.
Normally, an AV exception here would indicate that you have a buggy shell extension loaded into Windows Explorer.
Or your program has used P/Invoke or COM interop at some earlier point and corrupted your process's memory (which is easy to do which such things).
- Marked As Answer by Mike Dos ZhangMicrosoft Contingent Staff, Moderator Thursday, November 25, 2010 2:34 PM
-
Friday, November 05, 2010 7:09 AMModerator
Welcome to MSDN Forums!
In addition, you can create a new project in a new workspace to see if you can do this job.
I can execute the code, “this.openFileDialog1.ShowDialog();” (this code line is written in the child form), well in my side.
Please give us the response to let us know if your issue has been solved, and if not please provide more information related to the error message and code line.
If there’s anything unclear, please feel free to let me know.
Have a nice day!
Mike
*****************************************************
Sample world! You will get more from this world!
Welcome to the new world!
- Marked As Answer by Mike Dos ZhangMicrosoft Contingent Staff, Moderator Thursday, November 25, 2010 2:34 PM
-
Wednesday, March 09, 2011 4:03 PM
On windows 7 (32 bit) had same problem when showing the SaveFileDialog from a dot net windows form application (visual studio 2010, framework 4) with data from access db (access 2010) in it. Solution appeared to be: do not allow autoupgrade of dialog.
Dim sfv As New System.Windows.Forms.SaveFileDialog
With sfv
.AutoUpgradeEnabled = False
[...]
But error came up again. Then I noticed it was apparently randomic till I realized it did not come out if I was able to show a saveFileDialog or an OpenfileDialog before loading any data from db.Thus true workaround is: before load anything on the form you're going to show, display a dialog asking user to choose a path and file you *might* need after (arrrg!). After that, load data. Now your can let users, if needed, to choose path and file with dialog again...
ie:
Private Sub frmReport_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtFilePathName.Text = "Export_" & Now.ToString("yyyy_MM_dd_HH_mm_ss", CultureInfo.GetCultureInfo("it-It")) & ".csv"
txtFilePathName.Text = GetSaveFileName(txtFilePathName.Text, ".csv", "Choose a csv File to save exported data", "csv |*.csv|All |*.*")
'now load data in forms, where you can also have a button to call again the GetSaveFileName
[...]Private Function GetSaveFileName(ByVal fileName As String,
ByVal defaultExtension As String,
ByVal title As String,
ByVal filter As String) As String
Dim sfv As New System.Windows.Forms.SaveFileDialog
With sfv
.RestoreDirectory = True
.AddExtension = True
.DefaultExt = defaultExtension
.FileName = fileName
.Title = title
.Filter = filter
.CheckPathExists = True
.OverwritePrompt = True
.ShowHelp = FalseIf (.ShowDialog = DialogResult.OK) Then
fileName = .FileName
End If
End With
Return fileName
End FunctionCimperiali
-
Thursday, March 10, 2011 4:02 PMModerator
Hi Cimpy,
It seems that the issue is strange.
But I cannot very clear about your workaround, can you share us your test project, and let us know how to repro this issue in your test project?
You can upload your test project to the sky driver, and then show us the download link. Thanks.
I want to make sure if there's anything I was not really right.
It will also helped the others.
If there's any concern, please feel to let us know.
Have a nice day!
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Thursday, March 10, 2011 4:21 PM
I will, within 6 or 8 hours.
Regards,
Cesare
Cesare -
Thursday, March 10, 2011 10:50 PM
this is first time I use sky drive, so give me suggestion if it could have been shared differently
here is the link to the test project
The zipped project there (no bin, debug, exe or Obj; only project, net classes, an access 2010 db with a single table and 4 or 5 records in it and the folder "My Project": you will have to compile it) causes access violation (shared memory corrupted...) the second time you show the modal form and, in it, try to get the Save file dialog pressing the [...] button. It usually happens only after you get the dialog a first time, then close the dialog,, close the modal (remaining thus in first main form) and then show again the modal and try the [...] button again.
To avoid access violation, you should show an open file dialog in the modal form *before* load any data. From that on, you can show dialog again when you want.
Cesare- Edited by Cimpy - Cimperiali Friday, March 11, 2011 12:34 AM
-
Thursday, March 10, 2011 11:53 PMby the way, just realized this is C# forum...I will translate it in C# tomorrow. And second, juts saw servicepak 1 for Vs2010. I am dowloading and installing. Tomorrow I will be able to tell if it could made any difference.
Cesare -
Friday, March 11, 2011 12:31 PM
Here the same project in C#
By the way: I installed servicepack 1 for visual studio 2010 this morning and tested again: Access Violation is still there.
here the working but annoying workaorund:
Cesare -
Thursday, April 28, 2011 6:39 PM
Any luck getting a response from Microsoft on this Cimpy? You may have to post as a new thread, I don't think they pay much attention to threads that started six months ago.
I've got the same problem happening here for me on multiple PC's. Though I haven't been able to reliably reproduce it. I've had it happen w/in minutes, or go 1/2 day w/out seeing it.
I too have noticed that if you bring up a dialog box *before* you access the database you don't (seem to ever) get the error. Also, I only get it when using Access, not SQLExpress. Our PC's are 64bit Win7, so we're having to compile as x86 in order to use the 32-bit JET driver to access Access.
I've been able to open the dialog, hit cancel, open it again, and then it errors. I'm mentioning this because I don't think setting .InitialDirectory makes a difference. (But then again, who'd have thought using OLEDB would somehow break a file dialog box?)
It doesn't matter if you use namespace "System.Microsoft.Win32" or "System.Windows.Form" for your dialog (latter derives from the former anyway)
Stack trace is showing the exception occurring w/in the unmanaged code section of the Win32 code of the dialog box.
I've now turned on the Debug Unmanaged Code option, but haven't been able to reproduce the error just yet w/ that turned on. Maybe it'll show more information.
- Edited by eric-914 Thursday, April 28, 2011 6:55 PM Comment update
-
Thursday, April 28, 2011 9:03 PM
No answers at all, but I can survive: I show a dialog before any data load to get paths I need
I do believe it is a bug that should be worth to look in deeper by Microsoft team, but also there is Sql Server Express which is a valid alternative, so I think they will not fix it.
;-)
Cesare

