C#OpenFileDialog中的Stackoverflow / CLR错误

下面的代码是我悲伤的一个(三个)例子。 这是一个简单的OpenFileDialog()调用,导致程序崩溃。 在XP上,如果对话框保持打开几秒钟,则会发生崩溃。 在Vista上,如果用户选择“我的电脑”,则会发生崩溃。 在VS2008中,调试器有时会捕获stackoverflowexception。 如果我在第一行(新…)中放置一个断点,vshost.exe崩溃。 如果我在ShowDialog()行放置一个断点,我会得到一个FatalExecutionEngineError。 如果我在没有vshost的情况下编译,应用程序将运行直到随机崩溃(如在XP上 – 有一些时间)。

还有另外两个打开的对话框可以打开不同类型的文件,这三个文件都具有相同的行为。 类似的代码在我的其他项目中没有显示相同的行为。

线程公寓是单身。 我试过设置ValidateNames = false。 在大多数情况下,调试器正在脱离深层。

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

代码叫

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

在什么情况下显示此对话框的方法被调用? 此错误的最可能的来源是该事件多次生成并导致许多OpenFileDialog实例显示给用户。 它们可能显示在彼此之上,只显示一个对话框。

编辑

如果仅调试器方案失败,则尝试关闭隐式函数评估到调试器属性窗口(工具 – >选项 – >调试器)。 当通过调试器查看时,表单上的某个属性可能会导致堆栈溢出。

我添加到项目中的DLL导致堆损坏。 症状是奇怪而美丽的崩溃。