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

FileSavePicker throws "Invalid window handle" error #11527

Closed
datvm opened this issue Nov 21, 2022 · 3 comments
Closed

FileSavePicker throws "Invalid window handle" error #11527

datvm opened this issue Nov 21, 2022 · 3 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/windows 🪟 t/bug Something isn't working
Milestone

Comments

@datvm
Copy link

datvm commented Nov 21, 2022

Description

The following code throws an exception:

        var diag = new Windows.Storage.Pickers.FileSavePicker();
        diag.FileTypeChoices.Add("PDF", new List<string>() { ".pdf" });

        try
        {
            await diag.PickSaveFileAsync(); // Exception here
        }
        catch (Exception ex)
        {
            this.exceptionText = ex.ToString();
        }

System.Runtime.InteropServices.COMException (0x80070578): Invalid window handle. (0x80070578)
Consider WindowNative, InitializeWithWindow
See https://aka.ms/cswinrt/interop#windows-sdk
at MauiApp1.Pages.Index.SaveFileAsync()

image

Steps to Reproduce

  1. Create a MAUI app. Add the above code or use the repo below.
  2. Click "Save File" button.
  3. Exception is thrown.

Link to public reproduction project repository

https://github.com/datvm/MAUIWinPickerError

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

net7.0-windows10.0.19041.0

Did you find any workaround?

This supposes to fix it but right now I cannot find anyway to get a Window hWnd anymore. Also that issue is closed supposedly it's fixed but I am still encountering it right now: #2194 (comment). See #11527 (comment)

Relevant log output

No response

@datvm datvm added the t/bug Something isn't working label Nov 21, 2022
@datvm
Copy link
Author

datvm commented Nov 21, 2022

Found workaround for now (finally know how to get the window's hWnd):

            var currWin = Application.Current?.Windows.FirstOrDefault();
            var hwnd = (currWin?.Handler.PlatformView as MauiWinUIWindow)?.WindowHandle;
            if (hwnd is null) { return; }
            
            WinRT.Interop.InitializeWithWindow.Initialize(diag, hwnd.Value);

Thanks to #2194 (comment) and this

@Eilon Eilon added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Nov 21, 2022
@PureWeen PureWeen added this to the Backlog milestone Nov 22, 2022
@ghost
Copy link

ghost commented Nov 22, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mattleibow
Copy link
Member

This is the issue: microsoft/WindowsAppSDK#1063

@mattleibow mattleibow closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants