WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

InvalidCastException when trying to get string array from ApplicationData

Open tipa opened this issue 5 months ago • 3 comments

Describe the bug

When building the app with PublishAot=true, getting a string array from ApplicationData.Current.LocalSettings and casting it to the string[] type I get: System.InvalidCastException: 'Unable to cast object of type 'WinRT.IInspectable' to type 'System.String[]'.'

Steps to reproduce the bug

Set in csproj: <PublishAot>true</PublishAot>

ApplicationData.Current.LocalSettings.Values["test"] = new string[] { "a", "b", "c" };
var array = (string[])ApplicationData.Current.LocalSettings.Values["test"];

Expected behavior

No crash

Screenshots

image

NuGet package version

Windows App SDK 1.6.0: 1.6.240829007

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

Example project: Test.zip

tipa avatar Sep 10 '24 13:09 tipa