Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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'". #10257

Open
Junjun-zhao opened this issue Jan 10, 2025 · 5 comments
Labels
📭 waiting-author-feedback To request more information from author.

Comments

@Junjun-zhao
Copy link
Member

Junjun-zhao commented Jan 10, 2025

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

@h3xds1nz
Copy link
Contributor

This issue seems to be entirely CsWin32 related.

@miloush
Copy link
Contributor

miloush commented Jan 10, 2025

As in the repro case does not use WPF at all, there is no reason why this should be filed in this repo.

@Junjun-zhao Junjun-zhao changed the title [dotnet-sdk-10.0.100-alpha.1.25057.15] WinQuickLook get error: System.InvalidCastException: Unable to cast object of type 'System.__ComObject' to type 'Windows.Win32.UI.Shell.IShellView'. [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'". Jan 10, 2025
@Junjun-zhao
Copy link
Member Author

@h3xds1nz @miloush Thanks for looking at this issue. Could you please move it to the right area if this is not WPF? Thank you

@PriyaPurkayastha
Copy link

@AArnott or @jaredpar would one of you be able to look into this issue and help move it to the right repo? Thanks.

@harshit7962 harshit7962 added the 📭 waiting-author-feedback To request more information from author. label Jan 13, 2025
@jaredpar
Copy link
Member

@AaronRobinsonMSFT may have a suggestion here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📭 waiting-author-feedback To request more information from author.
Projects
None yet
Development

No branches or pull requests

6 participants