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, FileSavePicker, and FolderPicker break in WinUI3 Desktop #2716

Closed
eleanorleffler opened this issue Jun 19, 2020 · 27 comments
Closed
Assignees
Labels
appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps bug Something isn't working product-winui3 WinUI 3 issues team-Reach Issue for the Reach team

Comments

@eleanorleffler
Copy link

Describe the bug

The FileOpenPicker, FileSavePicker, and FolderPicker in the WinUI3 Desktop sample solution break and close the application.

Steps to reproduce the bug

  1. Clone the WinUI3 Problems FilePicker repository.

  2. Go to the FilePickerWinUI folder.

  3. Open the FilePickerWinUI solution in Visual Studio 2019 Preview.

  4. Build and run with Debug x64.

  5. Test each button

    A. FileOpenPicker

     1. Click the FileOpenPicker button.
     2. Select one or more files.
     3. Click [Open].
     4. The application will immediately close. 
    

    B. FileSavePicker

     1. Click the FileSavePicker button.
     2. The application should crash with an error. See Screenshot#1
    

    C. FolderPicker

     1. Click the FolderPicker button.
     2. Select one folder.
     3. Click [Select Folder].
     4. The application will immediately close.
    

Expected behavior

We expect the application to display the path of the selected file(s) or folder.

We expect the FileOpenPicker, FileSavePicker, and FolderPicker to allow the user to select files or a folder.

Screenshots

FilePickerError

Screenshot#1 - Current Behavior (Error Message)

FilePickerAppearance

Screenshot#2 - Application Appearance

Version Info

NuGet package version:
[Microsoft.VCRTForwarders.140 1.0.6]
[Microsoft.WinUI 3.0.0-preview1.200515.3]

Targeting:
Target: Universal Windows
Target version: Windows 10, version 1809 (10.0; Build 17763)
Min version: Windows 10, version 1809 (10.0; Build 17763)

Windows 10 version Saw the problem?
Insider Build (xxxxx)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763) Yes
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Mobile
Xbox
Surface Hub
IoT

Additional context

We copied the related C# code from the microsoft/WinUI-3-Demos.

You will see this in App.xaml.cs and MainWindow.xaml.cs.

If we set the Debug -> Debugger Type -> Application proccess to Native Only, then the FolderPicker will work without crashing. However, the other two buttons will still not work.

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Jun 19, 2020
@StephenLPeters StephenLPeters added the product-winui3 WinUI 3 issues label Jun 22, 2020
@StephenLPeters
Copy link
Contributor

StephenLPeters commented Jun 22, 2020

@stevenbrix and @Scottj1s, @llongley thinks this is a CSWinrt issue. FYI.

@StephenLPeters StephenLPeters added area-Tooling team-Markup Issue for the Markup team appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps labels Jun 22, 2020
@MikeHillberg
Copy link
Contributor

I can't tell from the documentation, it could be that these pickers don't work in a Desktop (hwnd rather than CoreWindow) app.

@azchohfi
Copy link
Contributor

azchohfi commented Jul 9, 2020

It works if no debugger is attached, or if the Native Only debugger is attached. This seems like a tooling issue, or a Dot Net Core runtime issue. I believe these pickers worked fine on Xaml Islands.

@marb2000 marb2000 added the bug Something isn't working label Jul 9, 2020
@TheMrJukes
Copy link

TheMrJukes commented Jul 28, 2020

I can't get any pickers to work at all in a Desktop (HWND) Win32 app using C++/WinRT.

necore\shell\lib\calleridentity\callerwindow_twinapi.cpp(116)\twinui.appcore.dll!00007FF8D3EC0BDC: (caller: 00007FF8D3E91E10) ReturnHr(1) tid(cd18) 80040155 Interface not registered
CallContext:[\PickSingleFileAsync\SingleStorageItemOperation]
Exception thrown at 0x00007FF905DD226C (KernelBase.dll) in App2.exe: WinRT originate error - 0x80070578 : 'Invalid window handle.'.
Exception thrown at 0x00007FF905DD226C in App2.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000305EF8CEE8.

winrt::fire_and_forget MainWindow::ShowPicker()
{
FileOpenPicker open;
open.SuggestedStartLocation(PickerLocationId::DocumentsLibrary);
open.FileTypeFilter().Append(L".txt");
auto file = co_await open.PickSingleFileAsync();
if (file)
{
}
}

EDIT:
I was pointed to a solution:
https://github.com/microsoft/WinUI-3-Demos/blob/0bc934a6716235a7f55e3f2a90f4dbb045a0697d/DemoBuildCpp/DemoBuildCpp/DemoBuildCpp/MainWindow.cpp#L140-L162

@jevansaks
Copy link
Member

Since WinUI3 allows multiple windows on the same thread, the pickers can no longer assume there's just one and use it as the owner. You will need to use the IInitializeWithWindow interface to give the hint. Looks like the documentation has been updated to give some clues about this now:

FileOpenPicker and IInitializeWithWindow.

@msft-github-bot msft-github-bot removed the needs-triage Issue needs to be triaged by the area owners label Sep 10, 2020
@placasse
Copy link

placasse commented Oct 9, 2020

This issue is closed but I still face the same exact issue and I can not find a solution in this thread.
The InitializeWithWindow was already used in the question (see screenshots).

The given workaround to "set the Debug -> Debugger Type -> Application proccess to Native Only" works but the hability to debug Managed code is considered essential in our development workflow so is not a long term solution.

I use
Visual studio 16.7.5
.Net SDK 5.0.100-preview.5.20279.10
WinUI 3.0.0-preview2.200713.0

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Oct 9, 2020
@stevenbrix
Copy link
Contributor

@angelazhangmsft are you able to confirm if this issue has been fixed? I thought there was an associated C#/WinRT issue for this, but am not seeing it in this thread.

@ghost ghost removed the needs-triage Issue needs to be triaged by the area owners label Oct 13, 2020
@angelazhangmsft
Copy link
Contributor

@Scottj1s @j0shuams do you know if this issue has been fixed?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Oct 13, 2020
@j0shuams
Copy link

j0shuams commented Oct 14, 2020

@angelazhangmsft From what I could tell these are not C#/WinRT issues. When I encountered this it was with XCG and had to do with their implementation -- I made an issue there microsoft/WinUI-Gallery#559

Doesn't look like it has been fixed. @stevenbrix is this the issue you are talking about? I think it is a different issue than the one discussed here.

@stevenbrix
Copy link
Contributor

@j0shuams the symptom of this issue is that debugging a .NET app with just the native debugger works, but when you attach the managed debugger, you get an issue. I can't tell from that linked issue whether that is the same issue as this one, but my gut is that it isn't (I could be wrong of course)

@ghost ghost removed the needs-triage Issue needs to be triaged by the area owners label Oct 14, 2020
@j0shuams
Copy link

@stevenbrix No I don't think the two are related (the issue I linked and this one). My understanding of the issue of this thread was it had to do with providing a window handle hint to Picker objects (FileSavePicker, etc). I don't think there is a C#/WinRT issue about debugging with managed being broken -- is that a C#/WinRT issue? I don't think I know enough to make that call; if you think so then youcould open an issue on that repo. Let me know how else I can help

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Oct 14, 2020
@jevansaks jevansaks reopened this Oct 14, 2020
@jevansaks
Copy link
Member

Apologies for closing this and missing that IInitializeWithWindow was already being used. I'll reopen this until folks figure out whether this is a WinUI3 or CSWinRT issue and route the bug report accordingly.

@marb2000
Copy link
Contributor

Thanks everybody for participating on this issue. I have updated the WinUI 3 Demos to the Preview 3 and it seems that every scenario works now.

I'll close the issue.

Regards!

@ghost ghost removed the needs-triage Issue needs to be triaged by the area owners label Nov 19, 2020
@marb2000 marb2000 self-assigned this Nov 19, 2020
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 23, 2020
@Austin-Lamb Austin-Lamb removed the needs-triage Issue needs to be triaged by the area owners label Jan 5, 2021
@wbokkers
Copy link

wbokkers commented Mar 1, 2021

The workaround described by @akanieski does only work when using PickSingleFileAsync().
An exception is still thrown when using PickMultipleFilesAsync().

See: https://gist.github.com/wbokkers/cc8bcc7bc5a646b82a4d41b337330c69#gistcomment-3649439

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Mar 1, 2021
@Austin-Lamb
Copy link

@wbokkers - I think that issue may be better tracked on the Project Reunion repo here: https://github.com/microsoft/ProjectReunion

Could you file that new issue there? Thanks!

@eleanorleffler
Copy link
Author

@Austin-Lamb @wbokkers I have created a new issue in the Project Reunion repository. See mentioned issue above!

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Apr 15, 2021
@nlogozzo
Copy link

I'm getting an error trying to use IInitializeWithWindow with a c++ app. #5218

@Crauzer
Copy link

Crauzer commented Sep 19, 2021

This still happens in .NET 6.0.100-rc.1.21458.32 using VS 2022 Preview in a MAUI Blazor project.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Sep 19, 2021
@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Oct 7, 2021
@xperiandri
Copy link

On .NET 6.0 RTM too

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 20, 2021
@xperiandri
Copy link

@marb2000 any info about that?

@d2phap
Copy link

d2phap commented Dec 5, 2021

Why is this closed while the API is still broken? @marb2000

@angelazhangmsft
Copy link
Contributor

The team is looking to improve the pattern for these APIs that require interop with IInitializeWithWindow. I've started a discussion at microsoft/WindowsAppSDK#1887!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps bug Something isn't working product-winui3 WinUI 3 issues team-Reach Issue for the Reach team
Projects
None yet
Development

No branches or pull requests