开发者

Issue with debugging Visual Studio 2010 solution that utilises FileDialog from the Vista API

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

  1. When running the application in Windows XP, the expectation is to provide the user with a Windows XP look-and-feel file dialog. When running the same application in Windows Vista and 7, the file dialog is to have a Vista look-and-feel.
  2. More importantly our application allows a user to open up a project file, which can either be a local file (stored on the user's machine or on a USB device), or a server project (hosted in MS SQL Server). To achieve this, we use the Vista API as we can access the event handler of the file-type drop-down-list control. Hence the implementation is such that the us开发者_C百科er is presented with the open file dialog, and when they select the "Server" option from the file-type drop-down-list, the open file dialog closes, and a different dialog opens, allowing the user to select the server they wish to connect to, and the server project.

In Visual Studio 2008 when debugging the application, there are no issues with the Vista API. When the solution is upgraded to Visual Studio 2010 (running in Windows 7), the user attempts to debug the application, and the user wishes to access the Vista API open file dialog, the application crashes with an ArgumentException being thrown with the following message: "Value does not fall within the expected range". Strangely enough when the user runs the solution without debugging (Ctrl + F5) from Visual Studio 2010, no exception occurs. The "offending" code is:

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 have tried some Google searching, but to no avail. I have available a sample Visual Studio 2010 solution with the Vista API, and the issue also occurs in this solution. The sample project can be downloaded (in ZIP form) from here. To reproduce the issue:

  1. Debug the solution in Visual Studio 2010.
  2. Once the "Vista Api Demo" is launched, click on the "Dialogs" tab.
  3. From the "Vista Look" column situated at the right hand side of the "Dialogs" tab, click on the "Open File" button.
  4. A dialog with the message "File type was changed to 1" will appear. Click on the OK button.
  5. Observe that at this point the application crashes, with the exception thrown from the DoFolderChange(IFileDialog) method in clsFileDialog.cs.

My apologies for the long-winded post, but I needed to explain the whole background of why the Vista API file dialog implementation is required. I appreciate any help in resolving this issue, as my development team is looking at working with Visual Studio 2010, and we developers do not want to be fiddling around with attaching and detaching the debugger just to bypass this issue.


I came across this and I figured out a fix 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();

I then 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 did not bomb on me anymore.

Mine was almost same scenario.

My scenario:

Code was WPF app under VS2008 and worked. (3.5 Framework was the Target Framework) I up-converted to code to VS2010 (4.0 Framework was the Target Framework). Then this new issue arose.

Both code bases were running on Windows 7 x64.

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

My full error was:

 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜