Stackoverflow / CLR error in C # OpenFileDialog

Below is one of three examples of my grief. This is a simple call to OpenFileDialog (), which causes the program to crash. XP crashes if the dialog remains open for several seconds. In Vista, a crash occurs if the user selects "My Computer". In VS2008, the debugger sometimes catches a stackoverflowexception. If I set a breakpoint on the first line (new ...), vshost.exe fails. If I put a breakpoint on the ShowDialog () line, I get FatalExecutionEngineError. If I compile without vshost, the application will work until a random crash (as on XP - there is a certain 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 is one apartment. I tried to set ValidateNames = false. In most cases, the debugger falls from depth.

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();
}

Event Handler Code:

// 
// 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);

Code called

    private void updateImageDisplay()
    {
        if (null != project.srcImage)
        {
            imageDisplay.SizeMode = PictureBoxSizeMode.Normal;
            if (project.srcImage != null)
            {
                imageDisplay.ClientSize = new Size(project.srcImage.Width, project.srcImage.Height);
                imageDisplay.Image = (Image)project.srcImage;
            }
            this.ScratchImage.Text = project.srcImageLocation;
        }
        else
        {
            imageDisplay.Image = null;
            this.ScratchImage.Text = "";
        }
        ImageDisplayPanel.Refresh();
    }
+3
source share
2 answers

In what circumstances is this a method that displays this dialog? The most likely source of this error is that the event is generated many times and causes many instances OpenFileDialogto be displayed to the user. They potentially appear on top of each other, creating only one dialog.

EDIT

, debugger ( β†’ β†’ ). , .

+5

DLL, , . .

+1

Source: https://habr.com/ru/post/1728955/


All Articles