I have a windows phone app and get sometimes InvalidOperationExceptions but not sure why and how to avoid them.
The problem function from the error report is Microsoft.Xna.Framework.Media.MediaLibraryEnumerator_1[[System.__Canon,_mscorlib]].get_Item
and i get this stacktrace
"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"
I also tried to add a try-catch block around the code block, but without a result
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;
}
Thanks for any suggestions
Not really one answer but if the error is one the first foreach
and the try
is on the second it's not catching the exception put the try
outside the
try
{
var root = new MediaLibrary().RootPictureAlbum;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With