我有一个 Windows 手机应用程序,有时会收到 InvalidOperationExceptions,但不知道为什么以及如何避免它们。错误报告中的问题函数是Microsoft.Xna.Framework.Media.MediaLibraryEnumerator_1[[System.__Canon,_mscorlib]].get_Item
,我得到了这个堆栈跟踪
"Frame Image Function Offset
0 Microsoft.Xna.Framework.ni.dll Microsoft.Xna.Framework.Media.MediaLibraryEnumerator_1[[System.__Canon,_mscorlib]].get_Item 0x0003e4d8
1 Microsoft.Xna.Framework.ni.dll Microsoft.Xna.Framework.Media.MediaLibraryEnumerator_1[[System.__Canon,_mscorlib]].System.Collections.IEnumerator.get_Current 0x00000006
2 Microsoft.Xna.Framework.ni.dll Microsoft.Xna.Framework.Media.MediaLibraryEnumerator_1[[System.__Canon,_mscorlib]].System.Collections.Generic.IEnumerator_T_.get_Current 0x0000001c
3 MapLense.ni.DLL MapLense.Helper.PictureMapping.Add 0x000000a8
4 MapLense.ni.DLL MapLense.Helper.PictureMapping+_GetPicture_d__b.MoveNext 0x000000f6
5 mscorlib.ni.dll System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess 0x00216c46
6 mscorlib.ni.dll System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification 0x0000003a
7 mscorlib.ni.dll System.Runtime.CompilerServices.TaskAwaiter_1[[System.__Canon,_mscorlib]].GetResult 0x0000001c
8 MapLense.ni.DLL MapLense.Helper.Map+_AddPictureToMap_d__17.MoveNext 0x00000118
9 mscorlib.ni.dll System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess 0x00216c46
10 mscorlib.ni.dll System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification 0x0000003a
11 mscorlib.ni.dll System.Runtime.CompilerServices.TaskAwaiter_1[[System.__Canon,_mscorlib]].GetResult 0x0000001c
12 MapLense.ni.DLL MapLense.MainPage+_ViewModelOnPropertyChanged_d__1e.MoveNext 0x00000204
13 mscorlib.ni.dll System.Runtime.CompilerServices.AsyncMethodBuilderCore._ThrowAsync_b__0 0x00000036"
我还尝试在代码块周围添加一个 try-catch 块,但没有结果
public static bool Add(DBPicture dbpicture)
{
if (Pictures.ContainsKey(dbpicture.UniqueID))
return true;
var root = new MediaLibrary().RootPictureAlbum;
foreach (var album in root.Albums)
{
if (album.Name != AppResources.CameraRollAlbumName) continue;
for (var i = 0; i < album.Pictures.Count; i++)
{
try
{
var picture = album.Pictures[i];
if (picture.Name == dbpicture.UniqueID)
{
Pictures.Add(picture.Name, picture);
DBPictures.Add(picture.Name, dbpicture);
return true;
}
}
catch (System.Exception e)
{
#if DEBUG
Logger.WriteLine("PictureMapping.Add(DBPicture)");
Logger.WriteLine(e);
#endif
}
}
}
return false;
}
感谢您的任何建议