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

Closed
Junjun-zhao opened this issue Jan 10, 2025 · 12 comments · Fixed by #112375
Assignees
Labels
area-Interop-coreclr in-pr There is an active PR which will close this issue when it is merged
Milestone

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
Member

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.

@jaredpar
Copy link
Member

@AaronRobinsonMSFT may have a suggestion here.

@Junjun-zhao
Copy link
Member Author

Hi @AaronRobinsonMSFT, could you please have a look at this issue and let us know if any suggestions? Thanks

@AaronRobinsonMSFT
Copy link
Member

@Junjun-zhao I'll take a look today.

@AaronRobinsonMSFT AaronRobinsonMSFT transferred this issue from dotnet/wpf Feb 10, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 10, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 10, 2025
@AaronRobinsonMSFT AaronRobinsonMSFT added area-Interop-coreclr and removed untriaged New issue has not been triaged by the area owner labels Feb 10, 2025
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 10.0.0 milestone Feb 10, 2025
@AaronRobinsonMSFT AaronRobinsonMSFT removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 10, 2025
@AaronRobinsonMSFT AaronRobinsonMSFT self-assigned this Feb 10, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

@AaronRobinsonMSFT
Copy link
Member

@Junjun-zhao Thanks for reporting this issue. This was introduced in #105965. I will put up a fix shortly.

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Feb 10, 2025
@Junjun-zhao
Copy link
Member Author

Thanks @AaronRobinsonMSFT for the quick fix. May I know whether this is a blocker for .NET 10 Preview 1 and the fix will be merged into the .NET 10 Preview1?

@AaronRobinsonMSFT
Copy link
Member

@Junjun-zhao Sorry, this is not a preview blocker. You should be able to get around this issue by removing the IOle interface from the definition of IShellView. I know this is being done via CsWin32 so that might be difficult, but the workaround is to not have your COM interface implement any other interface.

@Junjun-zhao
Copy link
Member Author

Verified on build dotnet-sdk-10.0.100-preview.2.25122.2, this issue has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Interop-coreclr in-pr There is an active PR which will close this issue when it is merged
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

6 participants