Showing an OpenFileDialog occasionally causes the application to hang

0

Most of the time, the OpenFileDialog is displayed with no issue, but on rare occasions, showing it causes the application to hang indefintely until the process is ended.

The OpenFileDialog is defined as below:

        var dialog = new OpenFileDialog
        {
            ValidateNames = false,
            CheckFileExists = false,
            CheckPathExists = true,
            FileName = "This Folder",
        };
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            //logic here
        }

Answers to similar questions suggest that the problem may be related to the DLLs my application is using.

Possibly relevant debug output of a successful run follows:

Whenever the program is launched:

...
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertutil.dll'. 
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\propsys.dll'. 
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00B3D034.
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
'Program Name.exe' (CLR v4.0.30319: Program Name.exe): Loaded 'Microsoft.GeneratedCode'. 
'Program Name.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\Microsoft.V9921e851#\10e86f631668518a182dfda3901d1848\Microsoft.VisualBasic.ni.dll'. 
...

The first time that the OpenFileDialog is shown within a program run:

...
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sxs.dll'. 
mincore\com\oleaut32\dispatch\ups.cpp(2125)\OLEAUT32.dll!77444221: (caller: 77444318) ReturnHr(1) tid(7cb0) 8002801D Library not registered.
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\StructuredQuery.dll'. 
...
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140.dll'. 
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140.dll'. 
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: Mso::RegistryException at memory location 0x0B15C968.
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msi.dll'. 
...

As opening the OpenFileDialog causes the application hang only rarely, I do not have any debug output for such a run.

None of the above exceptions are present when I run the application in its CLI mode.

I have tried researching the above exception messages, but this has not led me to a solution.

Do you know what might be causing this issue?

Do you have any suggestions on how I might proceed with debugging the problem?

c#
.net
dll
openfiledialog
asked on Stack Overflow Nov 8, 2019 by Sepia • edited Nov 8, 2019 by Sepia

1 Answer

-1

That happened to me too. It happened because the form that was calling openFileDialog was created in a different thread, but i still dont know why it happens. A possible workaroud is:

    var dialog = new OpenFileDialog
    {
        ValidateNames = false,
        CheckFileExists = false,
        CheckPathExists = true,
        FileName = "This Folder",
    };
    this.Hide();
    if (dialog.ShowDialog() == DialogResult.OK)
    {
        //logic here
    }
    this.Show();
answered on Stack Overflow Nov 8, 2019 by Luís Filipe

User contributions licensed under CC BY-SA 3.0