-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Bug] FilePicker throws COMException on Windows #2194
Comments
This appears to be a duplicate of #2102 (an Android bug), but it's interesting that it's also presenting in Windows. I wonder if the internals of FilePicker try to store a reference to the parent window? My issue happened with the MSAL authentication library, but only on Android, which needs a parent window reference to properly open the system browser. It did not show up on iOS, which doesn't need that reference. So I'm wondering if the MAUI Parent Window logic is the common thread here. |
This also happens for me on .NET 6 RC1 and VS2022 preview. I've also made sure to initialize the pickers with the HWND of the app window - https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/winrt-com-interop-csharp |
Where is this at? Do we have a timeline for when the fix to these will drop? |
For windows envrionment I was able to run it this way. It works flawlessly with both MAUI and MAUI-Blazor.
|
This should have been fixed with -> #3232
Should work... You need to add the OnActivated lifecycle event though: https://github.com/jamesmontemagno/maui/blob/b8674a83bac2ee394ff984587e4cfde2c6185bf2/src/Essentials/samples/Samples/Startup.cs I tried your code and got an exception though.. maybe something changed in v1 of the app sdk. Looking at https://github.com/microsoft/CsWinRT/blob/master/docs/interop.md#windows-sdk this is what we do.... so just not sure if this got merged into P11 |
I can't tell if Preview 11 got #3232 or not. However, my windows app is throwing a different exception now but that could be other changes in .NET MAUI...who knows? FilePicker.PickAsync() is now throwing "Source object type is not a projected type and does not inherit from a projected type. (Parameter 'value')" Is there a way to confirm whether #3232 made it into Preview 11? If not, is there a way to obtain a build of MAUI that does have it? Some kind of nightly build or something? |
I tried but I can't reach the CurrentWindowHandle in my Application. When I look at the source codes, I see that this property is internal. Is there any method to get this property (I added lifecycle event ) |
Testing with P11 getting, will look as the fix should be in there...: System.Runtime.InteropServices.COMException: 'Invalid window handle. (0x80070578) |
WinUI3 supports the IWindowNative interface, support is built into the C# WinRT runtime, eg: var window = new Microsoft.UI.Xaml.Window(); |
I don't think we want to create a new Window... we would want to use the current Active Window correct.... var hwnd = Platform.CurrentWindowHandle;
WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd);
SetFileTypes(options, picker);
var resultList = new List<StorageFile>();
if (allowMultiple)
{
var fileList = await picker.PickMultipleFilesAsync();
if (fileList != null)
resultList.AddRange(fileList);
}
else
{
var file = await picker.PickSingleFileAsync();
if (file != null)
resultList.Add(file);
} And for the internal static IntPtr CurrentWindowHandle
=> WinRT.Interop.WindowNative.GetWindowHandle(CurrentWindow); This is what I do today... @Redth thoughts? |
Yes, if the MAUI code is already tracking the current active window, that should work fine. |
@Redth just tested on mainline and it was working so doing some debugging around to see if somethign else is going on. |
Just tried this again with MAUI Preview 12 / Visual Studio 17.1 Preview 4 and I am now getting a different exception:
Unfortunately the call stack doesn't provide anything useful, it only shows the method I called |
Not reproducible with windows 10.0.19041. |
This is the issue: microsoft/WindowsAppSDK#1063 |
Description
On WinUI projects on the Windows platform, using the
PickAsync
andPickMultipleAsync
methods from the FilePicker class in Essentials results in aSystem.Runtime.InteropServices.COMException
being thrown. The error message returned in the exception is "Invalid window handle. (0x80070578)".I'm not sure if the issue lies within MAUI or WinUI itself.
Steps to Reproduce
Expected Behavior
The file open dialog should appear.
Actual Behavior
An exception is thrown and the application crashes.
Basic Information
The text was updated successfully, but these errors were encountered: