views:

387

answers:

2

The code below is one (of three) examples of my grief. It is a simple OpenFileDialog() call which causes the program to crash. On XP, the crash occurs if the dialog stays open for several seconds. On Vista, the crash occurs if the user selects "My Computer". In VS2008, the debugger sometimes catches a stackoverflowexception. If I put a break point in the first line (new ...), vshost.exe crashes. If I put a break point at the ShowDialog() line, I get a FatalExecutionEngineError. If I compile without vshost, the application will run until a random crash (as on XP - there is some amount of time).

There are two other open dialogs that open different types of files, all three of which have the same behavior. Similar code does not show the same behavior in my other projects.

The thread apartment is single. I have tried setting ValidateNames = false. The debugger is falling off the deep-end in most cases.

OpenFileDialog imageDlg = new OpenFileDialog();
imageDlg.Filter = "All Images|*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.bmp|All Files|*.*|JPEGs (*.jpg)|*.jpg|PNGs (*.png)|*.png|TIFFs (*.tiff)|*.tiff|TIFFs (*.tif)|*.tif|BMPS (*.bmp)|*.bmp";
imageDlg.Title = "Select Scan Image";

if (DialogResult.OK == imageDlg.ShowDialog())
{
    updateImageDisplay();
}


// // setScratchImageButton // 
this.setScratchImageButton.Location = new System.Drawing.Point(191, 15);
this.setScratchImageButton.Name = "setScratchImageButton";
this.setScratchImageButton.Size = new System.Drawing.Size(26, 23);
this.setScratchImageButton.TabIndex = 8; this.setScratchImageButton.Text = "...";
this.setScratchImageButton.UseVisualStyleBackColor = true;
this.setScratchImageButton.Click += new System.EventHandler(this.setScratchImageButton_Click);
+4  A: 

Under what circumstances is the method which displays this dialog being called? The most likely source of this error is that the event is being generated many times and causing many instances of OpenFileDialog to be displayed to the user. They are potentially being displayed on top of each other giving the appearance of only a single dialog.

EDIT

If it's only the debugger scenario that is failing then try turning off implicit function evaluation into debugger property windows (Tools -> Options -> Debugger). It's possible one of the properties on your form is causing a stack overflow when viewed through the debugger.

JaredPar
+1 - context is required. Stackoverflowexception often implies that the method is being called too many times.
keyboardP
The function is being called from code generated by the form designer.The code is instantiated from a single button click. I have confirmed that this code is added as an event only once in the code base (the function name exists exactly twice in the code base -- once in the designer code, and once in the function definition).I have determined that the same behavior also occurs for the save file dialog.The dialog remains open for perhaps 20 seconds prior to crashing -- I have confirmed that only a single instance of the dialog is open.
@unknown, can you post the event hookup code and the code for updateImageDisplay?
JaredPar
EDITS:I put the code requested in the original comment above.
Keep in mind, that I have 3 other functions that fail in the same way--2 other OpenFileDialog calls and one SaveFileDialog.I can't thank you enough for taking your time to help with this. I'm at my wit's end on this. I have 4 other projects that work fine with these calls -- I can't find an substantive difference between the code base.
How about cutting down the filter string just as a quick test. Just say: Filter = "All Files|*.*";
SwDevMan81
A: 

A DLL I had added to the project was causing heap corruption. The symptom was strange and beautiful crashes.