PresentationCore.dll中的ArgumentException

时间:2015-07-28 13:32:50

标签: c# wpf

我正在尝试使用电影封面创建WrapPanel。当我加载140封面时,一切正常,但是当我加载141封面时,

    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: 

我的代码看起来像那样

<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);
   }
}

如果有人能够解决这个问题,我将非常感激:(非常感谢!

2 个答案:

答案 0 :(得分:0)

内部异常::::::::::::::::::::::::::::::::::::::::::::::::::::::: enter image description here

答案 1 :(得分:0)

i.CreateOptions |= BitmapCreateOptions.IgnoreColorProfile;

Thanks to Rafael Rivera