1

I'm trying to create WrapPanel with movie covers. When i load 140 covers everything works fine, but when i load 141 covers then:

    System.ArgumentException was unhandled
  HResult=-2147024809
  Message=Value does not fall within the expected range.
  Source=PresentationCore
  StackTrace:
       at System.Windows.Media.ColorContext.GetColorContextsHelper(GetColorContextsDelegate getColorContexts)
       at System.Windows.Media.Imaging.BitmapFrameDecode.get_ColorContexts()
       at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
       at System.Windows.Media.Imaging.BitmapImage.OnDownloadCompleted(Object sender, EventArgs e)
       at System.Windows.Media.UniqueEventHelper.InvokeEvents(Object sender, EventArgs args)
       at System.Windows.Media.Imaging.LateBoundBitmapDecoder.DownloadCallback(Object arg)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run()
       at pCore.App.Main() in c:\Users\narkoze\Desktop\vanagz\pCore\pCore\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ArgumentException
       HResult=-2147024809
       Message=Value does not fall within the expected range.
       InnerException: 

My Code looks something like that:

<ScrollViewer>
 <WrapPanel Name="MyWrapPanel" x:FieldModifier="public" />
</ScrollViewer>

using (var client = new WebClient())
{
   var content = client.DownloadString("http://www.");
   var movies = JsonConvert.DeserializeObject<List<MovieAttributes>>(content);
   foreach (var movie in movies)
   {
      TextBox tb = new TextBox();
      tb.Text = movie.Name;

      Image img = new Image();
      BitmapImage bi = new BitmapImage();
      Uri cover = new Uri(movie.Cover, UriKind.RelativeOrAbsolute);
      bi.UriSource = cover;
      img.Source = bi;

      StackPanel sp = new StackPanel();
      sp.Children.Add(tb);
      sp.Children.Add(img);

      MyWrapPanel.Children.Add(sp);
   }
}

I'll be very grateful if anyone will be able to solve this problem :( Thank you very much!

b00sted 'snail'
  • 354
  • 1
  • 13
  • 27
  • 1
    Have you tried swapping the image file for number 141 for a different one? – Glen Thomas Jul 28 '15 at 13:41
  • Maybe it is because some image links are broken or on the link is no more image? Then how can i fix this? :/ How can i define - on http://...com/img.jpg there is image or not? Sorry for my bad english :( – b00sted 'snail' Jul 28 '15 at 13:58
  • Can you click on "View Detail" on the error window? Drill down into the **Inner Exceptions**, this should uncover the problem. – Mike Eason Jul 28 '15 at 14:29
  • The exception occurs while decoding your image. Have you checked the constructed URL to ensure that you are actually getting the image you are expecting? – Steve Mitcham Jul 28 '15 at 15:09
  • links ends with .jpg but i think sometimes on the link can be something like this : http://www.filmoo.ro/wp-content/uploads/2014/10/Addicted-2014.jpg – b00sted 'snail' Jul 28 '15 at 15:47
  • possible duplicate of [How do I catch this WPF Bitmap loading exception?](http://stackoverflow.com/questions/2732140/how-do-i-catch-this-wpf-bitmap-loading-exception) – Dour High Arch Jul 28 '15 at 18:29

2 Answers2

1
i.CreateOptions |= BitmapCreateOptions.IgnoreColorProfile;

Thanks to Rafael Rivera

Community
  • 1
  • 1
b00sted 'snail'
  • 354
  • 1
  • 13
  • 27
0

Inner Exceptions :::::::::::::::::::::::::::::::::::::::::: enter image description here

b00sted 'snail'
  • 354
  • 1
  • 13
  • 27