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

FileOpenPicker.PickSingleFileAsync() Causes a crash when app is started from an elevated context/tarted as Adminitrator #2731

Closed
mide25 opened this issue Jul 14, 2022 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@mide25
Copy link

mide25 commented Jul 14, 2022

Describe the bug

When a WIN UI 3 app is configured to start with elevated privileges by adding the allowElevation capability and setting the requestedExecutionLevel to requireAdministrator; invoking FileOpenPicker.PickSingleFileAsync() causes the application to crash (note: this is irrespective of IDE as it also crashes when I run outside of Visual Studio). On further investigation wrapping FileOpenPicker.PickSingleFileAsync() and logging the exception to a file gives the following error:

Error HRESULT E_FAIL has been returned from a call to a COM component.
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.

Checking the Event viewer logs shows:

Faulting module name: CoreMessagingXP.dll, version: 10.0.22621.1003, time stamp: 0xc93a5eeb
Exception code: 0xc000027b
Fault offset: 0x0000000000090e1c

Steps to reproduce the bug

Go to your application's Package.appxmanifest and add the capabilities:

<Capabilities>
    <rescap:Capability Name="runFullTrust" />
	<rescap:Capability Name="allowElevation"/>
  </Capabilities>

Go to the application's app.manifest and modify as follows:

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
	<security>
		<requestedPrivileges>
			<requestedExecutionLevel level="requireAdministrator"/>
		</requestedPrivileges>
	</security>
  </trustInfo>

Ensure your application has a button that triggers a FileOpenDialog. See sample below:

FileOpenPicker open = new FileOpenPicker();
InitializeWithWindow.Initialize(open, MainWindowPtr); //MainWindowPtr is the pointer to the main window of the app (i.e. parent of the current page that extends Window). This line attaches the dialog to the window of your app.
open.SuggestedStartLocation = PickerLocationId.ComputerFolder;
open.FileTypeFilter.Add(".exe");
StorageFile file = await open.PickSingleFileAsync();

Note that the app crashes/throws a COM exception

Expected behavior

It should pop up the select file/folder dialog even when the app is started with administrator privileges

Screenshots

No response

NuGet package version

1.1.2

Packaging type

Packaged (MSIX)

Windows version

Insider Build (xxxxx)

IDE

Visual Studio 2022

Additional context

No response

@btueffers btueffers added bug Something isn't working duplicate This issue or pull request already exists labels Jul 14, 2022
@btueffers
Copy link
Contributor

This is a duplicate of #2504 so we'll continue to track there.

fredemmott added a commit to OpenKneeboard/OpenKneeboard that referenced this issue Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants