Intermittent fatal exception opening file dialog
Description
One of our testers is seeing a very intermittent fatal exception attempting to open a file dialog to browse the file system. The application simply terminates, bypassing our main exception handler. Restarting the application and opening the file dialog in the same way with the same initial folder and filter is successful. This exception has occurred 3 times in hundreds of attempts over two weeks of testing.
Reproduction Steps
Various places in the application attempt to open a file dialog, which causes a very intermittent exception.
Expected behavior
No exception, file dialog is shown
Actual behavior
Unhandled exception occurs and application terminates.
Call stacks for 8.0.6 and 8.0.8
CoreCLR Version: 8.0.624.26715 .NET Version: 8.0.6 Description: The process was terminated due to an unhandled exception. Exception Info: exception code c0000005, exception address 00007FFD2B1C048E Stack: at Windows.Win32.UI.Shell.IFileDialog.Show(Windows.Win32.Foundation.HWND) at System.Windows.Forms.FileDialog.TryRunDialogVista(Windows.Win32.Foundation.HWND, Boolean ByRef) at System.Windows.Forms.FileDialog.RunDialog(IntPtr) at System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)
CoreCLR Version: 8.0.824.36612 .NET Version: 8.0.8 Description: The process was terminated due to an unhandled exception. Exception Info: exception code c0000005, exception address 00007FFA649AE46E Stack: at Windows.Win32.UI.Shell.IFileDialog.Show(Windows.Win32.Foundation.HWND) at System.Windows.Forms.FileDialog.TryRunDialogVista(Windows.Win32.Foundation.HWND, Boolean ByRef) at System.Windows.Forms.FileDialog.RunDialog(IntPtr) at System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)
Regression?
We have not seen this prior to updating to .NET 8, although it is so random that we can't confirm it does not exist prior to that.
Known Workarounds
No response
Configuration
Windows 10 Enterprise 22H2, build 19045.4894; Occurred with .NET 8.0.6 and 8.0.8 Desktop is in dark mode if that's relevant.
Other information
No response
@merriemcgaw do you feel that this is appropriate for dotnet/winforms? (I do not seem to have transfer rights to that repo)
I'll move it, but my guess is that this is a Windows issue, rather than WinForms.
@Olina-Zhang could your teams try to create a test app and see if we can reproduce this in-house? If we can, let's check whether frequency changes with .NET 9 or with different versions of Windows. Thanks!
@merriemcgaw We tried many times on Windows 10 Enterprise 22H2, but it didn't reproduce.
Based off of the exception code, it looks like we are dealing with an access violation. https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-imodalwindow-show indicates that the passed in parameter can be null, so if we are passing null in this scenario, this should not be an issue. It seems like the dialog itself has somehow gotten into a corrupt state, however on a cursory look there is nothing that stands out that we are doing on our end that would cause this as our set up code for the dialog currently does not return HRESULT meaning exception would have been thrown from OnBeforeVistaDialog or TryRunDialogVista if an error had occurred while setting up -- not within show().
Since there's nothing on our side we can see, and there isn't a consistent repro we have to close this issue. If there are more consistent repros in the future we can reopen to investigate further.