Open optsing opened 1 month ago
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.
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:
fileSavePicker.FileTypeChoices.Add("Test file", new List<string> { ".test" });
to this:
fileSavePicker.FileTypeChoices.Add("Test file", new[] { ".test" });
and it works.
More info:
<WindowsSdkPackageVersion>10.0.26100.45</WindowsSdkPackageVersion>
<PublishAot>true</PublishAot>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
I had the same problem and modified this line:
fileSavePicker.FileTypeChoices.Add("Test file", new List<string> { ".test" });
to this:
fileSavePicker.FileTypeChoices.Add("Test file", new[] { ".test" });
and it works.
More info:
<WindowsSdkPackageVersion>10.0.26100.45</WindowsSdkPackageVersion>
<PublishAot>true</PublishAot>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
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>
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