我正在尝试从我的应用程序中显示的艺术家,相册等音乐文件中获取属性,但是当它到达属性属性时,调试器会抛出异常,无法发布图像,因此消息为:
An unhandled exception of type 'System.AccessViolationException' occurred in UberPlayer.ni.DLL
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
我在想,因为它是在一个foreach上,它使用了大量的内存并且会中断,但是会像这样隔离代码:
IReadOnlyList<IStorageItemProperties> itemsListProperties = KnownFolders.MusicLibrary.GetFilesAsync().GetAwaiter().GetResult();
var test = itemsListProperties.First().Properties;
仍会收到异常消息,应用程序崩溃。
我是WP编程的新手,但我认为它不应该是代码错误。任何一个人?
我也在手机上运行调试,因为我的笔记本电脑无法模拟WP8.1
答案 0 :(得分:0)
我弄清楚发生了什么,
看起来类型IStorageItemProprieties不能从项目中检索属性,有趣的是他的名字,或者可能是它的被剥夺。
它适用于StorageFile类型,还添加了一些等待,也许我的速度太快了? :P
IAsyncOperation<IReadOnlyList<StorageFile>> async = KnownFolders.MusicLibrary.GetFilesAsync();
var itemsList = await async;
foreach (var item in itemsList)
{
var itemProp = item.Properties;
var propMusic = await itemProp.GetMusicPropertiesAsync();
Music m1 = new Music(propMusic.Title, propMusic.Artist, propMusic.Album, propMusic.Genre.ToString(), propMusic.TrackNumber.ToString(), propMusic.Duration, item.Path);
_listMusic.Add(m1);
}
return _listMusic;
感谢所有为讨论作出贡献的人。