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:
- The error doesn't seem to appear when I am debugging in VS. It appears only after I install the application using installer package.
- The error appears when I click a button which opens up a file explorer window to choose a file.
- But instead it crashes as soon as I click the button.
- the exception code associated to this problem in event viewer is 0xc000027b. But there is no accurate information related to this code.
- My application is currently intended to run on windows machine.
- 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.