Skip to content

Trying to use a FileOpenPicker while running the app as Administrator will crash the app #2504

Open

Description

Describe the bug

I am trying to open a File Picker but it works only if I am not using the app in elevation mode.

I'm getting the following error:

System.Runtime.InteropServices.COMException: 'Error HRESULT E_FAIL has been returned from a call to a COM component.'

The error appears when the code tries to execute the following line of code:

var file = await picker.PickSingleFileAsync();

Steps to reproduce the bug

  1. Create a WASDK app using version 1.4.2 and .NET 7
  2. Create an extension method so you can get the Window Handle

AppWindowExtension.cs

public static IntPtr GetHandle(this Microsoft.UI.Xaml.Window window)
{
    return WinRT.Interop.WindowNative.GetWindowHandle(window);
}
  1. Make the MainWindow available outside the App class

App.xaml.cs

public static Window MainWindow { get; private set; }
  1. Use the generated Button_Click event method to open the File Picker

MainWindow.xaml.cs

var picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");

InitializeWithWindow.Initialize(picker, App.MainWindow.GetHandle());

var file = await picker.PickSingleFileAsync();
  1. Build the app and try to Run as Administrator (it's not neccesary to configure elevation, just right click on the app works)
  2. Click the button to open the File Picker
  3. The app will crash :(

Expected behavior

I would expect this basic feature of picking a file to work even if I run the app as admin.
My app has a lot of features that require elevation so getting rid of elevation is not an option for me.

Screenshots

No response

NuGet package version

1.4.2

Packaging type

Packaged (MSIX)

Windows version

Insider Build (xxxxx) (only on Windows 11)

IDE

Visual Studio 2022

Additional context

The same for FolderPicker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions