InvalidOperationException with MediaLibrary Images

I have an application for a Windows phone and sometimes get InvalidOperationExceptions, but I don’t know why and how to avoid it. The problem function from the error report is up Microsoft.Xna.Framework.Media.MediaLibraryEnumerator_1[[System.__Canon,_mscorlib]].get_Item, and I get this stack trace

"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 adding a try-catch block around the code block, but with no 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.

+5
source share
3 answers

Actually not one answer, but if the error is one, the first foreachand tryis in the second, without catching an exception, put tryout

try
{
    var root = new MediaLibrary().RootPictureAlbum;
+1
source

. . , , WP8, . , , , . .

  • album.pictures
  • , album.pictures - album.Pictures.OrderBy(x=>x.Date);

, , .

0

WP 8.0. - "Camera Roll" . , "GetImage()". , GetImage() . - ( ) . , .

, .

0

All Articles