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

Unable to retrieve string list properties from files #1942

Open
vgromfeld opened this issue Mar 6, 2025 · 1 comment
Open

Unable to retrieve string list properties from files #1942

vgromfeld opened this issue Mar 6, 2025 · 1 comment

Comments

@vgromfeld
Copy link

Description

The list of artists for an audio file is stored in the System.Music.Artist property as a list of strings.
We can get this property value using StorageItemContentProperties.RetrievePropertiesAsync.
When casting the returned property object with CsWinRT, the code is throwing an InvalidCastException.
This is working fine in a regular UWP application.
I tried other interfaces IEnumerable<string>, IList<string>, ICollection<string>, IReadOnlyCollection<string>,... but none of them are working 😟

Steps To Reproduce

Add the following code in a .NET9 UWP application:

var picker = new FileOpenPicker
{
    SuggestedStartLocation = PickerLocationId.MusicLibrary,
};
picker.FileTypeFilter.Add(".mp3");

var file = await picker.PickSingleFileAsync();
var properties = await file.Properties.RetrievePropertiesAsync(PropertyNames);

var value = (IReadOnlyList<string>)properties[FilePropertyNames.Artist]; // <--- throws InvalidCastException

I've checked all the following types and none of them are matching:

var type = properties[FilePropertyNames.Artist] switch
{
    IReadOnlyList<string> => "readonlylist",
    IReadOnlyCollection<string> => "readonlycollection",
    Windows.Foundation.Collections.IObservableVector<string> => "observable vector",
    IList<string> => "list",
    ICollection<string> => "collection",
    IEnumerable<string> => "enumerable",

    IReadOnlyList<object> => "readonlylist object",
    IReadOnlyCollection<object> => "readonlycollection object",
    Windows.Foundation.Collections.IObservableVector<object> => "observable vector object",
    IList<object> => "list object",
    ICollection<object> => "collection object",
    IEnumerable<object> => "enumerable object",
    _ => "unknown",
};

Expected Behavior

The returned list of strings should be castable to a .Net string list object

Version Info

TargetFramework = net9.0-windows10.0.26100.0
Microsoft.Windows.CsWinRT nuget = 2.2.0

Additional Context

Sample application: FileProperties.zip

@dongle-the-gadget
Copy link
Contributor

This is a known issue at the moment, as CsWinRT does not support generic interface casting in AOT mode, which UWP .NET 9 enables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants