Skip to content

[dotnet-sdk-10.0.100-alpha.1.25057.15] Fail to open folder in WinQuickLook with error "System.InvalidCastException: Unable to cast object of type 'System.__ComObject' to type 'Windows.Win32.UI.Shell.IShellView'". #112371

@Junjun-zhao

Description

@Junjun-zhao

Description

When run the 3rd party application with the latest .NET 10 build, it was no response to open folder. After investigation, we discovered this error: System.InvalidCastException: Unable to cast object of type 'System.__ComObject' to type 'Windows.Win32.UI.Shell.IShellView'.

Reproduction Steps

App Repro Steps:

  1. Open "WinQuickLookApp\WinQuickLook.App.runtimeconfig.json" file .
    2.Change the "WinQuickLook.App.runtimeconfig.json" file to let the app run against with
    dotnet-sdk-10.0.100-alpha.1.25057.15.
"frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "10.0.0-alpha.1.25052.4"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "10.0.0-alpha.1.25056.2"
      }
    ],
  1. Run the ”WinQuickLook\App\WinQuickLook\WinQuickLook.App.exe”.
  2. Open the folder "WinQuickLook\AdditionFiles\WinQuickLook"
  3. Choose the “Test” folder.
  4. Press a space-key.

Expected Result:
Pop up window.

Actual Result:
No window show.

Minimal Repro steps (Demo attached: WpfAppDemo.zip):

  1. Create a default 8.0 WPF project.
  2. Add the following code in WpfAppDemo.csproj.
<Platform>x64</Platform>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
  1. Install package Microsoft.Windows.CsWin32 0.3.106.
  2. Add the following code in Mainwindow.xaml.cs.
using System.Windows;
using Windows.Win32;
using Windows.Win32.UI.Shell;
using IServiceProvider = Windows.Win32.System.Com.IServiceProvider;
namespace WpfAppDemo
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            var shellWindows = (IShellWindows)new ShellWindows();
            shellWindows.get_Count(out var count);
            for (var i = 0; i < count; i++)
            {
                shellWindows.Item(i, out IWebBrowserApp webBrowserApp);
                webBrowserApp.get_HWND(out var hwnd);

                var serviceProvider = (IServiceProvider)webBrowserApp;

                serviceProvider.QueryService(PInvoke.SID_STopLevelBrowser, out IShellBrowser shellBrowser);

                shellBrowser.QueryActiveShellView(out var shellView);
            }
        }
    }
}
  1. Copy all file from attachment to project.
  2. Build the project.
  3. Change the runtime.config file to let the app run against with dotnet-sdk-10.0.100-alpha.1.25057.15:
"frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "10.0.0-alpha.1.25052.4"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "10.0.0-alpha.1.25056.2"
      }
    ],
  1. Launch the app.

Expected behavior

Launch successfully.

Actual behavior

Launch failed with error: System.InvalidCastException: Unable to cast object of type 'System.__ComObject' to type 'Windows.Win32.UI.Shell.IShellView'.

Regression?

Yes

Verify Scenarios:
1). Windows 10 22H2 AMD64 + dotnet-sdk-9.0.102: Pass
2). Windows 10 22H2 AMD64 + dotnet-sdk-10.0.100-alpha.1.25057.15: Fail

Known Workarounds

No response

Impact

No response

Configuration

Application Name: WinQuickLook
OS: Windows 10 22H2
CPU: X64
.NET Build Number: dotnet-sdk-10.0.100-alpha.1.25057.15
App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2340552
Github Link: https://github.com/shibayan/WinQuickLook

Dotnet info:

.NET SDK:
 Version:           10.0.100-alpha.1.25057.15
 Commit:            39da6dde11
 Workload version:  10.0.100-manifests.a166a9cf
 MSBuild version:   17.14.0-preview-25056-07+8d395fd27

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.100-alpha.1.25057.15\

Host:
  Version:      10.0.0-alpha.1.25052.4
  Architecture: x64
  Commit:       efdd299533

.NET SDKs installed:
  10.0.100-alpha.1.25057.15 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 10.0.0-alpha.2.25056.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 10.0.0-alpha.1.25052.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 10.0.0-alpha.1.25056.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other information

@dotnet-actwx-bot @dotnet/compat

Metadata

Metadata

Labels

area-Interop-coreclrin-prThere is an active PR which will close this issue when it is merged

Type

No type
No fields configured for issues without a type.

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions