Description
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