问题与调试Visual Studio 2010的解决方案,利用的FileDialog从Vista的API解决方案、问题、Studio、Visual

2023-09-07 04:02:41 作者:摆摊ζ卖寂莫ǒ

我有一个WinForms C#的Visual Studio 2008(.NET 3.5)解决方案,升级到Visual Studio 2010(.NET将维持在3.5版)。该溶液利用的FileDialog距离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:

当运行在Windows XP应用程序,期望是提供与​​Windows XP的外观和感觉的文件对话框的用户。当运行在Windows Vista和7相同的应用程序,文件对话框是有一个Vista的外观和感觉。 更重要的是我们的应用程序允许用户在打开一个项目文件,它可以是本地文件(存储在USB设备上的用户的机器上还是在),或一个服务器项目(托管MS SQL Server中)。为了实现这一目标,我们使用Vista的API,我们可以访问文件类型下拉列表控件的事件处理程序。因此,实现这样的用户是psented的打开文件对话框$ P $,当他们选择从文件类型下拉列表中的服务器选项,打开文件对话框关闭,并且不同的对话框打开,允许用户选择他们希望连接到服务器,并且该服务器项目。

在Visual Studio 2008中调试应用程序的时候,也有与Vista的API没有问题。当解决方案升级到Visual Studio 2010(在Windows 7中运行),用户试图调试应用程序,而用户希望访问Vista API打开文件对话框,有一个ArgumentException应用程序崩溃被抛出以下消息: 值没有在预期的范围之内。当用户运行从Visual Studio 2010的解决方案,无需调试(Ctrl + F5键)奇怪的是,没有异常发生。而得罪code是:

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);
}

我已经尝试了一些谷歌搜索,但都无济于事。余可用一个样品的Visual Studio 2010与Vista中的API溶液中,该问题也发生在该溶液中。示例项目可以从这里下载(以ZIP​​格式)。要重现该问题:

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:

调试在Visual Studio 2010中的解决方案。 当Vista的阿比演示推出后,点击对话框选项卡上。 从Vista的外观列位于的对话框选项卡的右侧,点击打开文件按钮。 与消息的对话框的文件类型改为1将出现。单击OK按钮。 在观察,在这一点上,应用程序崩溃,除了从DoFolderChange(IFileDialog)方法clsFileDialog.cs抛出。

我道歉的长篇大论后,但我需要解释为什么Vista的API文件对话框,要求实现整个背景。我AP preciate解决这个问题,因为我的开发团队的帮助正在寻找与Visual Studio 2010的工作,我们的开发人员不想与安装和拆卸调试器只是为了绕过这个问题摆弄周围。

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.

原来的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();

和它并没有给我弹了。

我的是几乎相同的情况。

Mine was almost same scenario.

我的情况:

code是WPF应用程序VS2008下和工作。 (3.5框架为目标框架) 我上变成code到VS2010(4.0框架为目标框架)。那么这个新的问题出现了。

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.

这两个code碱基,在Windows 7 64位系统上运行。

Both code bases were running on Windows 7 x64.

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

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

我完全错误是:

 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()