-
Notifications
You must be signed in to change notification settings - Fork 329
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
Windows.Storage.Pickers.FileSavePicker.FileTypeChoices.Add throw System.InvalidCastException: 'Specified cast is not valid.' with PublishAOT=true #4743
Comments
Can anybody suggest a workaround for this? Our project needs both the file save picker and AOT, so this bug is a showstopper for us. |
You can call the file save picker via win32 api as described at the end of this article: https://learn.microsoft.com/en-us/uwp/api/windows.storage.pickers.filesavepicker?view=winrt-26100 To make the CsWin32 package work with AOT you need to specify “allowMarshaling”: false in NativeMethods.json and correct the original example a bit. |
@optsing Awesome! Works great, thank you. |
I had the same problem and modified this line:
to this:
and it works. More info: |
Does it work in a new blank project? I have it working in a large project, even with collection expression, but it doesn't work in a smaller or empty one, even with string array or List<string> |
Unfortunately no, it doesn't. I started migrating one of my apps from .NET Native to .NET 9 (UWP) and my workaround doesn't work at all. I haven’t checked it in an empty Windows App SDK project yet. |
This is a common bug for UWP NET and WindowsAppSDK and was solved in CSWinRT 2.2. So the actual solution is to add a reference to the CSWinRT package version >= 2.2 for both types of projects. I think this issue should be open as long as this bug is present in a blank project. |
Describe the bug
Windows.Storage.Pickers.FileSavePicker.FileTypeChoices.Add throw System.InvalidCastException: 'Specified cast is not valid.' with PublishAOT=true
With PublishAOT=false everything works fine.
Steps to reproduce the bug
<WindowsSdkPackageVersion>10.0.22621.45</WindowsSdkPackageVersion>
and<PublishAot>true</PublishAot>
to csprojExpected behavior
After clicking on the button, the Save File dialog box should be displayed
Screenshots
No response
NuGet package version
Windows App SDK 1.6.0: 1.6.240829007
Packaging type
Packaged (MSIX)
Windows version
Insider Build (xxxxx)
IDE
Visual Studio 2022-preview
Additional context
No response
The text was updated successfully, but these errors were encountered: