1

I'm encountering an issue with a .NET MAUI application where I'm using the FilePicker.PickAsync method to allow users to pick image files. However, I'm consistently getting the following error:

Error HRESULT E_FAIL has been returned from a call to a COM component.

The error stack trace points to the FilePickerImplementation.PlatformPickAsync method within the Microsoft.Maui.Storage namespace. Here's the relevant part of the stack trace:

at Microsoft.Maui.Storage.FilePickerImplementation.PlatformPickAsync(PickOptions options, Boolean allowMultiple)
   at Microsoft.Maui.Storage.FilePickerImplementation.PickAsync(PickOptions options)
   at MyApplication.Platforms.Windows.CustomFilePicker.ImageFilePicker(String TitleMessage)
   at MyApplication.Views.Settings_View.OnBrowserClicked(Object sender, EventArgs e)

Steps to Reproduce:

  1. The error doesn't seem to appear when I am debugging in VS. It appears only after I install the application using installer package.
  2. The error appears when I click a button which opens up a file explorer window to choose a file.
  3. But instead it crashes as soon as I click the button.
  4. the exception code associated to this problem in event viewer is 0xc000027b. But there is no accurate information related to this code.
  5. My application is currently intended to run on windows machine.
  6. Therefore I created a custom file picker service in the windows platform specific folder

Code Example: Here's a simplified version of the code I'm using to invoke the file picker:

public async Task < string > ImageFilePicker(string TitleMessage)
{
    var result = await FilePicker.PickAsync(new PickOptions
    {
        PickerTitle = TitleMessage,
        FileTypes = FilePickerFileType.Images
    });
    var signaturePath = result?.FullPath.ToString();
    return signaturePath;
}

Additional Context:

I'm running the .NET MAUI application exclusively on Windows. I am running the app as administrator I'm using the latest version of .NET MAUI community toolkit

Has anyone encountered a similar issue with the FilePicker.PickAsync method in a .NET MAUI application on Windows? What could be causing this error, and how can I resolve it?

I expect the file picker to open and allow me to select an image file. However, I'm encountering the "Error HRESULT E_FAIL has been returned from a call to a COM component" consistently.

As a workaround I have tried adding capabilities to package.appxmanifest file as follows but that didn't resolve the issue.

<Capabilities>
    <rescap:Capability Name="packageManagement" />
    <Capability Name="internetClient"/>
    <Capability Name="privateNetworkClientServer"/>
    <uap:Capability Name="removableStorage"/>
    <uap:Capability Name="picturesLibrary"/>
    <uap:Capability Name="videosLibrary"/>
</Capabilities

As I mentioned before I have also created a customFilePicker class in windows platform specific folder and created customImageFilePicker method.

1 Answers1

0

After looking into it, I figured out why it was happening and found a way to fix it. It seems the issue is due to how permissions are handled.

Here's what I found: When I first installed the app without using "Run as Administrator," it set up the app data folder with permissions tied to the user account I was logged in with. Later, when I tried running the app as an administrator, it crashed when I tried to use the file picker.

The problem is that the app treats administrator privileges as if they belong to a different user, not the same one who set up the app. So, when the file picker tries to open the file explorer, it's like the app doesn't recognize the current user and crashes.

To make things work, I suggest installing the app normally, without using "Run as Administrator." Then, when you use the app, just run it regularly, without administrator rights. This way, it should work without any issues.