-
Notifications
You must be signed in to change notification settings - Fork 693
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
OpenFileDialog is not working with WinUI3 preview 2 and .NET5 preview 7 for desktop app development #3295
Comments
@stevenbrix This sound really familiar, do you remember something like this (a cswinrt bug causing file picker to fail)? |
@anshul-rohilla can you take a look at https://github.com/microsoft/WinUI-3-Demos/tree/master/DemoBuildCs? This should be fixed by Preview3 so that you don't have any awkward steps or weird wrappers |
@StephenLPeters @stevenbrix thank you so much for providing updates. I will wait for Preview 3, meanwhile I will check the demo link you have provided. |
This is still failing with preview 3. Any update on the issue? |
This is still not working in preview 4. Here are some details: <TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<PackageReference Include="Microsoft.WinUI" Version="3.0.0-preview4.210210.4" /> private async Task LoadFileAsync()
{
var picker = new FileOpenPicker
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary
};
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
await picker.PickSingleFileAsync();
} Calling this method will throw Edit: I could get it to work by using the solution from this comment. |
The workaround mentioned by @cornem is not working when using PickMultipleFilesAsync() |
This issue is still present in May 2022 - Windows App SDK 1.1.0-preview3. What's the deal? |
Which issue ? WinRT.Interop.InitializeWithWindow.Initialize works fine for me, with PickSingleFileAsync or PickMultipleFilesAsync |
Using this way, I get the same issue.
If i use the fix mentioned above, I get I am on windows 11 22000 and using Windows App SDK 1.1.0-preview3 @castorix Can you post your full code? |
Nevermind, this actually was a different issue caused by running the app as admin. See #2504 |
The interop workaround is working OK. I'm just surprised that the OpenFileDialog doesn't work. The discussion at microsoft/WindowsAppSDK#1887 goes into the steps that MS will take to slightly improve the code steps to workaround over the short-term and mentions that long term (haha - seriously) the API will work as expected. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
I recently started migrating an old desktop app to WinUI3. The application has simple UI but complex backend business logic. I started with creating a blank new desktop application using WinUI3 preview 2 and .NET5 preview 7 and then slowly built the new UI. Everything looks great until I encountered problem with file browser functionality. OpenFileDialog is not recognized and build is failing. I have tried following:
Use FileOpenPicker instead of OpenFileDialog
No compile time error but failed on runtime as FileOpenPicker is built for UWP.
Tried changing the SDK to "Microsoft.NET.Sdk.WindowsDesktop"
It fixes the issue with OpenFileDialog, but many other issues start surfacing.
Tried changing target framework to "net5.0-windows"
Visual Studio is not recognizing the target framework at all.
Can someone please help me out here? This is the only blocker I have.
The text was updated successfully, but these errors were encountered: