Debug issue with Visual Studio 2010 solution that uses FileDialog from Vista API

I have a WinForms C # Visual Studio 2008 (.NET 3.5) solution that needs to be upgraded to Visual Studio 2010 (.NET will remain on version 3.5). This solution uses FileDialog from the Vista API for two reasons:

  • When running the application on Windows XP, the expectation is to provide the user with a Windows XP-style search dialog box. When starting the same application in Windows Vista and 7, the file dialog should look like Vista.
  • More importantly, our application allows the user to open a project file, which can be either a local file (stored on a user computer or a USB device) or a server project (hosted in MS SQL Server). To do this, we use the Vista API, as we can access the event handler of the file type drop-down control. Therefore, the implementation is such that the user is presented with an open file dialog box, and when they select the "Server" option in the file type drop-down list, the file open dialog is closed and another dialog box opens, allowing the user to select the server to which they want connect and server project.

In Visual Studio 2008, when debugging an application, there is no problem with the Vista API. When the solution is updated to Visual Studio 2010 (runs on Windows 7), the user tries to debug the application, and the user wants to access the Open API Vista dialog box, the application crashes with an ArgumentException with the following message: "The value is not in the expected range." Oddly enough, when a user launches a solution without debugging (Ctrl + F5) from Visual Studio 2010, there are no exceptions. Abusive code:

internal void DoFolderChange(IFileDialog dialog) { IShellItem ppsi = null; string ppszName = string.Empty; dialog.GetFolder(out ppsi); // Exception occurs here ppsi.GetDisplayName(NativeMethods.SIGDN.SIGDN_FILESYSPATH, out ppszName); OnFolderChange(ppszName); } 

I tried google search but to no avail. I have a sample Visual Studio 2010 solution with the Vista API, and the problem also occurs in this solution. A sample project can be downloaded (in ZIP format) from here . To reproduce the problem:

  • Debug a solution in Visual Studio 2010.
  • After starting "Vista Api Demo" click on the "Dialogs" tab.
  • In the Vista Look column located on the right side of the Dialogs tab, click the Open File button.
  • A dialog box appears with the message "The file type has been changed to 1". Click OK.
  • Please note that at this moment the application crashes with an error that was excluded from the DoFolderChange (IFileDialog) method in clsFileDialog.cs.

My apologies for the long post, but I needed to explain the whole background why the implementation of the Vista API dialog box is required. I am very grateful for the help in solving this problem, since my development team is working on Visual Studio 2010, and we do not want the developers to try to combine and separate the debugger in order to get around this problem.

+2
source share
1 answer

I came across this and I decided to fix it in my case.

Original code:

 OpenFileDialog fdlg = new OpenFileDialog(); string tempDirectoryName = @"..\SomeFolder\"; /* Note, the use of a relative directory*/ fdlg.InitialDirectory = tempDirectoryName ; Nullable<bool> result = fdlg.ShowDialog(); 

Then I changed it to:

 OpenFileDialog fdlg = new OpenFileDialog(); string tempDirectoryName = @"..\SomeFolder\"; /* Note, the use of a relative directory*/ string massagedDirectoryName = System.IO.Path.**GetFullPath**(tempDirectoryName); fdlg.InitialDirectory = massagedDirectoryName; /*Note, this is now the full folder name */ Nullable<bool> result = fdlg.ShowDialog(); 

And it no longer bombed me.

Mine was almost the same scenario.

My scenario:

The code was a WPF application in VS2008 and worked. (3.5 Framework was the target structure) I converted to code in VS2010 (4.0 Framework was the Target Framework). Then a new problem arose.

Both codebases were running on Windows 7 x64.

.............

My complete mistake:

  Value does not fall within the expected range. at MS.Internal.Interop.HRESULT.ThrowIfFailed(String message) at MS.Internal.AppModel.ShellUtil.GetShellItemForPath(String path) at Microsoft.Win32.FileDialog.PrepareVistaDialog(IFileDialog dialog) at Microsoft.Win32.FileDialog.RunVistaDialog(IntPtr hwndOwner) at Microsoft.Win32.CommonDialog.ShowDialog() 
0
source

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


All Articles