【问题标题】:WPF designer throwing strange errorWPF设计师抛出奇怪的错误
【发布时间】:2015-07-12 09:30:19
【问题描述】:

这是 VS2013 Pro,我正在开发 WPF 桌面应用程序。我面临的问题是,当我在设计器窗口中移动鼠标时,WPF 设计器会引发异常。这是它显示的堆栈跟踪:

System.NullReferenceException
Object reference not set to an instance of an object.
at MS.Utility.FrugalStructList`1.Add(T value)
at System.Windows.Media.PointCollection.CloneCurrentValueCore(Freezable source)
at System.Windows.Freezable.CloneCoreCommon(Freezable sourceFreezable, Boolean useCurrentValue, Boolean cloneFrozenValues)
at System.Windows.Freezable.CloneCurrentValueCore(Freezable sourceFreezable)
at System.Windows.Freezable.CloneCurrentValue()
at System.Windows.Media.PathSegmentCollection.CloneCurrentValueCore(Freezable source)
at System.Windows.Freezable.CloneCoreCommon(Freezable sourceFreezable, Boolean useCurrentValue, Boolean cloneFrozenValues)
at System.Windows.Freezable.CloneCurrentValueCore(Freezable sourceFreezable)
at System.Windows.Freezable.CloneCurrentValue()
at System.Windows.Media.PathFigureCollection.CloneCurrentValueCore(Freezable source)
at System.Windows.Freezable.CloneCoreCommon(Freezable sourceFreezable, Boolean useCurrentValue, Boolean cloneFrozenValues)
at System.Windows.Freezable.CloneCurrentValueCore(Freezable sourceFreezable)
at System.Windows.Freezable.CloneCurrentValue()
at System.Windows.Media.PathGeometry.GetAsPathGeometry()
at System.Windows.Media.GeometryHitTestParameters..ctor(Geometry geometry)
at Microsoft.Expression.XamlPlatform.Views.XamlHitTestHelper.PerformHitTest(HitTestParameters hitTestParameters, HitTestModifier hitTestModifier, InvisibleObjectHitTestModifier invisibleObjectHitTestModifier, ICollection`1 ignoredElements, Boolean stopAfterFirstHit, Boolean skipFullyContainedSelectionInObject, ViewHitTestFilterCallback filterCallback)
at Microsoft.Expression.XamlPlatform.Views.XamlSceneView.GetElementsInRectangle(Rect rectangle, HitTestModifier hitTestModifier, InvisibleObjectHitTestModifier invisibleObjectHitTestModifier, Boolean skipFullyContainedSelectionInObject)
at Microsoft.Expression.XamlPlatform.Views.XamlSceneView.HitElementHelper.GetSelectableElementsInRectangle(Rect rectangle)
at Microsoft.Expression.XamlPlatform.Views.XamlSceneView.GetSelectableElementAtPoint(Point point, SelectionFor3D selectionFor3D, Boolean selectedOnly, Boolean smartInvisiblePanelSelect)
at Microsoft.Expression.DesignSurface.View.SceneView.GetCachedSelectableElementAtPoint(Point point, SelectionFor3D selectionFor3D)
at Microsoft.Expression.DesignSurface.Tools.Selection.ElementEditorBehavior.OnHoverOverNonAdorner(Point pointerPosition)
at Microsoft.Expression.DesignSurface.Tools.ElementToolBehavior.OnHover(Point pointerPosition)
at Microsoft.Expression.DesignSurface.Tools.EventRouter.ScopeElement_MouseMove_Internal(MouseEventArgs args)
at Microsoft.Expression.DesignSurface.Tools.EventRouter.ThrottledEventHandler`1.HandleEventNow()
at Microsoft.Expression.DesignSurface.Tools.EventRouter.ThrottledEventHandler`1.ScheduleEventHandling(Args args, Double interval)
at Microsoft.Expression.DesignSurface.Tools.EventRouter.ScopeElement_MouseMove(Object sender, MouseEventArgs args)
at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(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.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 Microsoft.Expression.DesignHost.Isolation.DesignerProcess.RunApplication()
at Microsoft.Expression.DesignHost.Isolation.DesignerProcess.<>c__DisplayClass2.<Main>b__0()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
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()

我使用this SO post 的帮助附加了另一个 Visual Studio 实例,它在异常中中断,但整个调用堆栈都是外部代码,我看不出有什么问题。还有其他人遇到过这个吗?这是我能解决的问题吗?

【问题讨论】:

  • 不确定是否有帮助,但请确保您已安装最新的 VS 更新(更新 5 RC)。我知道在更新 5 中修复了一个问题,即打开设计器会导致“虚拟内存不足”错误

标签: .net wpf xaml crash designer


【解决方案1】:

提示是FrugalStructList。在研究该问题时,由于样式问题会发生其他空引用异常。

缩小问题范围的攻击计划

  1. 看看样式,有没有尝试过的样式 对特定数据类型进行处理?如果是这样,是否由于处于设计模式而失败,因为空数据上下文导致了问题?
  2. 注释掉所有控件并一一添加,直到您无法确定问题所在的控件。当发现控件是否正确处理空依赖值?如果不添加更多的空检查。
  3. 设计模式很特殊,仍然需要通过检查后端数据处理来适应它。在任何可能试图处理空值的代码上方添加(如果不是)if (!DesignerProperties.IsInDesignModeProperty)

【讨论】:

  • 感谢您的意见。突然间,问题自动为我解决了。最好的(最差的?)部分是我不必对代码进行任何更改。我也不必为它安装任何东西。就好像我早上醒来,它运行得很顺利。我会留意的。
猜你喜欢
  • 2019-09-21
  • 1970-01-01
  • 1970-01-01
  • 2017-07-25
  • 2018-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-25
相关资源
最近更新 更多