ShellFileDialogs icon indicating copy to clipboard operation
ShellFileDialogs copied to clipboard

Unexpected HRESULT: 0x0000 returned from IModalWindow.Show(...)

Open Profy opened this issue 3 years ago • 9 comments

I always get this error when using your library, regardless of the function used (open a folder, open a file...). Tests were done with the demo program. The cancel works very well.

System.Runtime.InteropServices.ExternalException
  HResult=0x00000000
  Message=Unexpected HRESULT: 0x0000 returned from IModalWindow.Show(...).
  Source=ShellFileDialogs
  StackTrace:
   at ShellFileDialogs.Utility.ValidateDialogShowHResult(HResult dialogHResult) in C:\Users\Marc\Documents\ShellFileDialogs\ShellFileDialogs\Utility.cs:line 212
   at ShellFileDialogs.FolderBrowserDialog.ShowDialogInner(IFileOpenDialog dialog, IntPtr parentHWnd, String title, String initialDirectory) in C:\Users\Marc\Documents\ShellFileDialogs\ShellFileDialogs\Dialogs\FolderBrowserDialog.cs:line 63
   at ShellFileDialogs.FolderBrowserDialog.ShowDialog(IntPtr parentHWnd, String title, String initialDirectory) in C:\Users\Marc\Documents\ShellFileDialogs\ShellFileDialogs\Dialogs\FolderBrowserDialog.cs:line 19
   at ShellFileDialogs.Demo.Program.Main(String[] args) in C:\Users\Marc\Documents\ShellFileDialogs\ShellFileDialogs.Demo\Program.cs:line 17

Doing some debugging, I saw TryGetWin32ErrorCode always returns false. The condition if( GetFacility( hr ) == HResultFacility.Win32 ) (l.142) always returns false.

Framework target : .NET 4.8

Profy avatar Jun 09 '22 17:06 Profy

The reason for the error is simple. When the HResult returns a success value, it is 0. The bitwise operation performed in GetFacility will therefore always return zero. TryGetWin32ErrorCode should return true if 0 <= hr.

Profy avatar Jun 10 '22 11:06 Profy

I'm unable to reproduce the issue at my end - can you please post a simple minimal project that reproduces the issue?

daiplusplus avatar Jun 11 '22 08:06 daiplusplus

Of course! ShellFileDialogsDemo.zip

It is a build made directly after git-clone (Merge branch 'dev/2021-04-nullable'). The only difference is that the assembly has not been signed.

ShellFileDialogs target framework: net48 Demo target framework: net48 IDE: Visual Studio 2022 Test Environment: Windows 10 Professional (21H2 - 19044.1741)

Profy avatar Jun 11 '22 09:06 Profy

Thanks - I can repro it in the ShellFileDialogs.Demo.exe - curious...

I'll look at this this weekend.

daiplusplus avatar Jun 11 '22 10:06 daiplusplus

Any updates on this issue?

I wanted to try the nuget package. So for now I will just try to use the source code.

Zexyp avatar Oct 19 '22 20:10 Zexyp

A pull request to resolve this issue has been suggested: https://github.com/Jehoel/ShellFileDialogs/pull/4.

Otherwise, there is a fork that integrates this fix and a support for selecting multiple folders: https://github.com/Profy/ShellFileDialogs

Profy avatar Oct 20 '22 07:10 Profy

Already found it. Works very well. Thanks

Zexyp avatar Oct 24 '22 10:10 Zexyp

Also hitting this issue. Any update ?

mikea314 avatar Jan 02 '23 21:01 mikea314