下面的代码会抛出 invalidOperationException,但前提是调试器已分离。该代码以 7.1 为目标,用户不时报告问题。这是我第一次可以在 windows phone 8 设备上重现此问题,但仅在我分离调试器时。附加调试器后,代码运行良好。这个问题不是一致的再现。在分析中,我看到一小部分用户面临这个问题。知道这里发生了什么吗?
PictureAlbum localRoll = media.GetCameraRoll();
foreach (Picture pic in localRoll.Pictures) // exception here
{
}
public PictureAlbum GetCameraRoll()
{
// Work around for known bug in the media framework. Hits the static constructors
// so the user does not need to go to the picture hub first.
MediaPlayer.Queue.ToString();
MediaLibrary ml = null;
PictureAlbum cameraRoll = null;
foreach (MediaSource source in MediaSource.GetAvailableMediaSources())
{
if (source.MediaSourceType == MediaSourceType.LocalDevice)
{
ml = new MediaLibrary(source);
PictureAlbumCollection allAlbums = ml.RootPictureAlbum.Albums;
foreach (PictureAlbum album in allAlbums)
{
if (album.Name == "Camera Roll")
{
cameraRoll = album;
return cameraRoll;
}
}
}
}
return null;
}
System.InvalidOperationException:发生意外错误。在 Microsoft.Xna.Framework.Media.MediaLibraryEnumerator'1.System.Collection.Ienumerator'1.get_Item(Int32 索引)