代码之家  ›  专栏  ›  技术社区  ›  Thomas Levesque

当堆栈中没有我的代码时,如何调试此错误?

  •  4
  • Thomas Levesque  · 技术社区  · 14 年前

    我知道如何解决这种错误,但在这种情况下我不知道 哪里 它正在发生,所以我不知道该怎么解决。。。异常的堆栈跟踪只包含.NET framework代码,不包含我的代码(除了Main方法):

       at System.Windows.Freezable.EnsureConsistentDispatchers(DependencyObject owner, DependencyObject child)
       at System.Windows.Freezable.OnFreezablePropertyChanged(DependencyObject oldValue, DependencyObject newValue, DependencyProperty property)
       at System.Windows.Freezable.OnFreezablePropertyChanged(DependencyObject oldValue, DependencyObject newValue)
       at System.Windows.Media.RenderData.PropagateChangedHandler(EventHandler handler, Boolean adding)
       at System.Windows.UIElement.RenderClose(IDrawingContent newContent)
       at System.Windows.Media.VisualDrawingContext.CloseCore(RenderData renderData)
       at System.Windows.Media.RenderDataDrawingContext.DisposeCore()
       at System.Windows.Media.DrawingContext.System.IDisposable.Dispose()
       at System.Windows.Media.RenderDataDrawingContext.Close()
       at System.Windows.UIElement.Arrange(Rect finalRect)
       at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)
       at System.Windows.Controls.ContentPresenter.ArrangeOverride(Size arrangeSize)
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
       at System.Windows.UIElement.Arrange(Rect finalRect)
       at System.Windows.Controls.WrapPanel.arrangeLine(Double v, Double lineV, Int32 start, Int32 end, Boolean useItemU, Double itemU)
       at System.Windows.Controls.WrapPanel.ArrangeOverride(Size finalSize)
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
       at System.Windows.UIElement.Arrange(Rect finalRect)
       at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)
       at System.Windows.Controls.ItemsPresenter.ArrangeOverride(Size arrangeSize)
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
       at System.Windows.UIElement.Arrange(Rect finalRect)
       at System.Windows.Controls.Border.ArrangeOverride(Size finalSize)
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
       at System.Windows.UIElement.Arrange(Rect finalRect)
       at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
       at System.Windows.UIElement.Arrange(Rect finalRect)
       at System.Windows.Controls.Border.ArrangeOverride(Size finalSize)
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
       at System.Windows.UIElement.Arrange(Rect finalRect)
       at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
       at System.Windows.UIElement.Arrange(Rect finalRect)
       at System.Windows.ContextLayoutManager.UpdateLayout()
       at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
       at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       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, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       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.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at MyApplication.App.Main() in E:\MyApplication\MyApplication\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
    

    由于应用程序相当复杂,因此手动检查可以在另一个线程中执行的所有代码实际上不是一个选项。。。

    任何建议都将不胜感激!

    3 回复  |  直到 14 年前
        1
  •  2
  •   Thomas Levesque    14 年前

    好吧,我终于找到了解决办法。。。

    在我的一个ViewModels中,我从主题资源加载了一个笔刷列表。在某些情况下,此ViewModel是从工作线程使用的。我假设XAML资源字典中定义的Freezable被隐式冻结,但显然不是这样。。。所以我只需要明确地冻结它们,这就解决了问题。

        2
  •  1
  •   Ron Warholic    14 年前

    您是否在后台工作人员的DOwork处理程序中动态添加一些UI控件?

        3
  •  0
  •   Timores    14 年前

    这应该告诉您涉及哪些DependencyObjects。

    您是否在GUI线程之外的另一个线程中创建DependencyObjects?可能在回调方法中?

    推荐文章