Trace.Assert 没有中断,也不显示消息框

发布于 2024-08-12 05:20:02 字数 11390 浏览 3 评论 0原文

我有一个 WPF 应用程序,我在其中在画布上移动数据。 当我像怪物一样尝试用鼠标移动数据时,问题就开始了。

以下是操作的顺序:

  • 画布上的 MouseMove 被触发
  • 在 MouseMove 中,我更改了一些数据
  • Trace.Assert 失败。调试器不会中断,消息框也不会
  • 中断另一个 MouseMove 被触发
  • 数据再次更改
  • 由于集合中的重入检查而引发异常。调试器在那里中断。断言消息框从未显示。

这里的大问题是我可以回到断言,但它不是断言失败时的数据,而是最后修改的数据......所以基本上我无法正确调试。

这是从第一个 MouseMove 开始的堆栈跟踪(注意 ShowMessageBoxAssert 以及它仍在继续的事实...):

  .Models.FCurve.MoveKey(int keyIndex = 3, double keyTime = 1182.0) Line 199 C#
  .Models.FCurve.KeyTimeChanged(Models.FCurveKey timeChangeKey = {Models.FCurveKey}) Line 186 + 0x2d bytes C#
  .Models.FCurve.AddKeyToArray.AnonymousMethod(object sender = {Models.FCurveKey}, System.EventArgs args = {System.EventArgs}) Line 163 + 0x11 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  .Models.FCurveKey.OnTimeChanged() Line 45 + 0x14 bytes C#
  .Models.FCurveKey..ctor.AnonymousMethod(object sender = {FCurveEditorTestApp.Impl.FCurveKeyImpl}, System.EventArgs args = {System.EventArgs}) Line 18 + 0x8 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.OnTimeChanged() Line 43 + 0x14 bytes C#
  FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.Time.set(double value = 1182.0) Line 34 + 0x8 bytes C#
  .Models.FCurveKey.Time.set(double value = 1182.0) Line 36 + 0x1b bytes C#
  .ViewModels.CurveKeyViewModel.X.set(double value = 1182.0) Line 32 + 0x2b bytes C#
  .ViewModels.CurveAreaViewModel.MoveSelectedItem.AnonymousMethod(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) Line 127 + 0x2d bytes C#
  Collections.CollectionHelper.ForEach(System.Collections.Generic.IEnumerable source = {System.Linq.Enumerable.OfTypeIterator}, System.Action action = {Method = {Void b__8(ViewModels.CurveKeyViewModel)}}) Line 31 + 0xe bytes C#
  .ViewModels.CurveAreaViewModel.MoveSelectedItem(double deltaX = 693.0, double deltaY = 35.0) Line 126 + 0x63 bytes C#
  .Views.CurveAreaView._AreaCanvas_MouseMove(object sender = {System.Windows.Controls.Canvas}, System.Windows.Input.MouseEventArgs e = {System.Windows.Input.MouseEventArgs}) Line 195 + 0x2d bytes C#
  PresentationCore.dll!System.Windows.Input.MouseEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) + 0x34 bytes 
  PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x27 bytes 
  PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) + 0x3e bytes 
  PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.Canvas}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs}, bool reRaised = false) + 0x1bf bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.Canvas}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs}) + 0x79 bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs}, bool trusted) + 0x35 bytes 
  PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x311 bytes 
  PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) + 0x42 bytes 
  PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) + 0x62 bytes 
  PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) + 0x2e2 bytes 
  PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804, ref bool handled = false) + 0x22b bytes 
  PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804, ref bool handled = false) + 0x75 bytes 
  WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804, ref bool handled = false) + 0xbe bytes 
  WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x7a bytes 
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = {System.Object DispatcherCallbackOperation(System.Object)}}, object args = {MS.Win32.HwndSubclass.DispatcherOperationCallbackParameter}, bool isSingleParameter = true) + 0x8a bytes 
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) + 0x44 bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) + 0x91 bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x40 bytes 
  WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804) + 0xdc bytes 
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  System.dll!System.Diagnostics.AssertWrapper.ShowMessageBoxAssert(string stackTrace, string message, string detailMessage) + 0x103 bytes 
  System.dll!System.Diagnostics.DefaultTraceListener.Fail(string message, string detailMessage) + 0xb2 bytes 
  System.dll!System.Diagnostics.DefaultTraceListener.Fail(string message) + 0xa bytes 
  System.dll!System.Diagnostics.TraceInternal.Fail(string message = "") + 0xb6 bytes 
  System.dll!System.Diagnostics.Trace.Assert(bool condition) + 0x1c bytes 
  .ViewModels.CurvePathViewModel.CurvePathViewModel(Models.FCurveKey startKey = {Models.FCurveKey}, Models.FCurveKey endKey = {Models.FCurveKey}, ViewModels.IInterpolationProvider interpolatorProvider = {ViewModels.InterpolationInfoProvider}) Line 29 + 0x4e bytes C#
  .ViewModels.CurvePathViewModel.CurvePathViewModel(ViewModels.CurveKeyViewModel startKey = {ViewModels.CurveKeyViewModel}, ViewModels.CurveKeyViewModel endKey = {ViewModels.CurveKeyViewModel}, ViewModels.IInterpolationProvider interpolatorProvider = {ViewModels.InterpolationInfoProvider}) Line 20 + 0x81 bytes C#
  .ViewModels.CurveViewModel.UpdateSegmentForKey(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) Line 215 + 0x41 bytes C#
  .ViewModels.CurveViewModel.KeyViewModelsChanged(object sender = Count = 13, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) Line 187 + 0x30 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x50 bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedAction action, object item, int index, int oldIndex) + 0x34 bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.MoveItem(int oldIndex, int newIndex) + 0x6f bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.Move(int oldIndex, int newIndex) + 0xe bytes 
  Collections.CollectionSynchronizer._SourceList_CollectionChanged(object sender = Count = 13, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) Line 239 + 0x45 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  WindowsBase.dll!System.Collections.ObjectModel.ReadOnlyObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args) + 0x1d bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ReadOnlyObservableCollection.HandleCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0xe bytes 
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x50 bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedAction action, object item, int index, int oldIndex) + 0x34 bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.MoveItem(int oldIndex, int newIndex) + 0x6f bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.Move(int oldIndex, int newIndex) + 0xe bytes 
  .Models.FCurve.MoveKey(int keyIndex = 1, double keyTime = 489.0) Line 199 + 0x19 bytes C#
  .Models.FCurve.KeyTimeChanged(Models.FCurveKey timeChangeKey = {Models.FCurveKey}) Line 186 + 0x2d bytes C#
  .Models.FCurve.AddKeyToArray.AnonymousMethod(object sender = {Models.FCurveKey}, System.EventArgs args = {System.EventArgs}) Line 163 + 0x11 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  .Models.FCurveKey.OnTimeChanged() Line 45 + 0x14 bytes C#
  .Models.FCurveKey..ctor.AnonymousMethod(object sender = {FCurveEditorTestApp.Impl.FCurveKeyImpl}, System.EventArgs args = {System.EventArgs}) Line 18 + 0x8 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.OnTimeChanged() Line 43 + 0x14 bytes C#
  FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.Time.set(double value = 489.0) Line 34 + 0x8 bytes C#
  .Models.FCurveKey.Time.set(double value = 489.0) Line 36 + 0x1b bytes C#
  .ViewModels.CurveKeyViewModel.X.set(double value = 489.0) Line 32 + 0x2b bytes C#
  .ViewModels.CurveAreaViewModel.MoveSelectedItem.AnonymousMethod(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) Line 127 + 0x2d bytes C#
  Collections.CollectionHelper.ForEach(System.Collections.Generic.IEnumerable source = {System.Linq.Enumerable.OfTypeIterator}, System.Action action = {Method = {Void b__8(ViewModels.CurveKeyViewModel)}}) Line 31 + 0xe bytes C#
  .ViewModels.CurveAreaViewModel.MoveSelectedItem(double deltaX = 82.0, double deltaY = -9.0) Line 126 + 0x63 bytes C#
  Views.CurveAreaView._AreaCanvas_MouseMove(object sender = {System.Windows.Controls.Canvas}, System.Windows.Input.MouseEventArgs e = {System.Windows.Input.MouseEventArgs}) Line 195 + 0x2d bytes C#

问题是:为什么会发生这种情况,以及我应该做什么才能使其在断言时中断?

我想过使用异常,也许是为了调试,但这确实是我需要的断言。我也在考虑所有其他断言,而不需要总是将它们转换为异常以进行调试......

I have a WPF application in which I'm moving data around on a Canvas.
The problem started when I tried moving the data with the mouse like a freak.

Here's the sequence of the actions:

  • The MouseMove on the Canvas is triggered
  • In the MouseMove, I change some data
  • A Trace.Assert FAILS. The debugger does not break, neither is the message box
  • Another MouseMove is triggered
  • The data is changed again
  • An exception is thrown because of a reentrancy check in a collection. The debugger breaks there. The Assert message box was never shown.

The big problem here is that I can go back to the assert, but it's not the data at the time the assert failed, but the modified data at the end... so basically I can't debug that correctly.

Here's the stack trace, starting from the first MouseMove (Notice the ShowMessageBoxAssert and the fact that it still goes on...):

  .Models.FCurve.MoveKey(int keyIndex = 3, double keyTime = 1182.0) Line 199 C#
  .Models.FCurve.KeyTimeChanged(Models.FCurveKey timeChangeKey = {Models.FCurveKey}) Line 186 + 0x2d bytes C#
  .Models.FCurve.AddKeyToArray.AnonymousMethod(object sender = {Models.FCurveKey}, System.EventArgs args = {System.EventArgs}) Line 163 + 0x11 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  .Models.FCurveKey.OnTimeChanged() Line 45 + 0x14 bytes C#
  .Models.FCurveKey..ctor.AnonymousMethod(object sender = {FCurveEditorTestApp.Impl.FCurveKeyImpl}, System.EventArgs args = {System.EventArgs}) Line 18 + 0x8 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.OnTimeChanged() Line 43 + 0x14 bytes C#
  FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.Time.set(double value = 1182.0) Line 34 + 0x8 bytes C#
  .Models.FCurveKey.Time.set(double value = 1182.0) Line 36 + 0x1b bytes C#
  .ViewModels.CurveKeyViewModel.X.set(double value = 1182.0) Line 32 + 0x2b bytes C#
  .ViewModels.CurveAreaViewModel.MoveSelectedItem.AnonymousMethod(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) Line 127 + 0x2d bytes C#
  Collections.CollectionHelper.ForEach(System.Collections.Generic.IEnumerable source = {System.Linq.Enumerable.OfTypeIterator}, System.Action action = {Method = {Void b__8(ViewModels.CurveKeyViewModel)}}) Line 31 + 0xe bytes C#
  .ViewModels.CurveAreaViewModel.MoveSelectedItem(double deltaX = 693.0, double deltaY = 35.0) Line 126 + 0x63 bytes C#
  .Views.CurveAreaView._AreaCanvas_MouseMove(object sender = {System.Windows.Controls.Canvas}, System.Windows.Input.MouseEventArgs e = {System.Windows.Input.MouseEventArgs}) Line 195 + 0x2d bytes C#
  PresentationCore.dll!System.Windows.Input.MouseEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) + 0x34 bytes 
  PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x27 bytes 
  PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) + 0x3e bytes 
  PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.Canvas}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs}, bool reRaised = false) + 0x1bf bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.Canvas}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs}) + 0x79 bytes 
  PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseEventArgs}, bool trusted) + 0x35 bytes 
  PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x311 bytes 
  PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) + 0x42 bytes 
  PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) + 0x62 bytes 
  PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) + 0x2e2 bytes 
  PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804, ref bool handled = false) + 0x22b bytes 
  PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804, ref bool handled = false) + 0x75 bytes 
  WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804, ref bool handled = false) + 0xbe bytes 
  WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x7a bytes 
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {Method = {System.Object DispatcherCallbackOperation(System.Object)}}, object args = {MS.Win32.HwndSubclass.DispatcherOperationCallbackParameter}, bool isSingleParameter = true) + 0x8a bytes 
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x4a bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler) + 0x44 bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) + 0x91 bytes 
  WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x40 bytes 
  WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 2628604, int msg = 512, System.IntPtr wParam = 1, System.IntPtr lParam = 30409804) + 0xdc bytes 
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  System.dll!System.Diagnostics.AssertWrapper.ShowMessageBoxAssert(string stackTrace, string message, string detailMessage) + 0x103 bytes 
  System.dll!System.Diagnostics.DefaultTraceListener.Fail(string message, string detailMessage) + 0xb2 bytes 
  System.dll!System.Diagnostics.DefaultTraceListener.Fail(string message) + 0xa bytes 
  System.dll!System.Diagnostics.TraceInternal.Fail(string message = "") + 0xb6 bytes 
  System.dll!System.Diagnostics.Trace.Assert(bool condition) + 0x1c bytes 
  .ViewModels.CurvePathViewModel.CurvePathViewModel(Models.FCurveKey startKey = {Models.FCurveKey}, Models.FCurveKey endKey = {Models.FCurveKey}, ViewModels.IInterpolationProvider interpolatorProvider = {ViewModels.InterpolationInfoProvider}) Line 29 + 0x4e bytes C#
  .ViewModels.CurvePathViewModel.CurvePathViewModel(ViewModels.CurveKeyViewModel startKey = {ViewModels.CurveKeyViewModel}, ViewModels.CurveKeyViewModel endKey = {ViewModels.CurveKeyViewModel}, ViewModels.IInterpolationProvider interpolatorProvider = {ViewModels.InterpolationInfoProvider}) Line 20 + 0x81 bytes C#
  .ViewModels.CurveViewModel.UpdateSegmentForKey(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) Line 215 + 0x41 bytes C#
  .ViewModels.CurveViewModel.KeyViewModelsChanged(object sender = Count = 13, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) Line 187 + 0x30 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x50 bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedAction action, object item, int index, int oldIndex) + 0x34 bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.MoveItem(int oldIndex, int newIndex) + 0x6f bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.Move(int oldIndex, int newIndex) + 0xe bytes 
  Collections.CollectionSynchronizer._SourceList_CollectionChanged(object sender = Count = 13, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) Line 239 + 0x45 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  WindowsBase.dll!System.Collections.ObjectModel.ReadOnlyObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args) + 0x1d bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ReadOnlyObservableCollection.HandleCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0xe bytes 
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x50 bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedAction action, object item, int index, int oldIndex) + 0x34 bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.MoveItem(int oldIndex, int newIndex) + 0x6f bytes 
  WindowsBase.dll!System.Collections.ObjectModel.ObservableCollection.Move(int oldIndex, int newIndex) + 0xe bytes 
  .Models.FCurve.MoveKey(int keyIndex = 1, double keyTime = 489.0) Line 199 + 0x19 bytes C#
  .Models.FCurve.KeyTimeChanged(Models.FCurveKey timeChangeKey = {Models.FCurveKey}) Line 186 + 0x2d bytes C#
  .Models.FCurve.AddKeyToArray.AnonymousMethod(object sender = {Models.FCurveKey}, System.EventArgs args = {System.EventArgs}) Line 163 + 0x11 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  .Models.FCurveKey.OnTimeChanged() Line 45 + 0x14 bytes C#
  .Models.FCurveKey..ctor.AnonymousMethod(object sender = {FCurveEditorTestApp.Impl.FCurveKeyImpl}, System.EventArgs args = {System.EventArgs}) Line 18 + 0x8 bytes C#
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.OnTimeChanged() Line 43 + 0x14 bytes C#
  FCurveEditorTestApp.exe!FCurveEditorTestApp.Impl.FCurveKeyImpl.Time.set(double value = 489.0) Line 34 + 0x8 bytes C#
  .Models.FCurveKey.Time.set(double value = 489.0) Line 36 + 0x1b bytes C#
  .ViewModels.CurveKeyViewModel.X.set(double value = 489.0) Line 32 + 0x2b bytes C#
  .ViewModels.CurveAreaViewModel.MoveSelectedItem.AnonymousMethod(ViewModels.CurveKeyViewModel key = {ViewModels.CurveKeyViewModel}) Line 127 + 0x2d bytes C#
  Collections.CollectionHelper.ForEach(System.Collections.Generic.IEnumerable source = {System.Linq.Enumerable.OfTypeIterator}, System.Action action = {Method = {Void b__8(ViewModels.CurveKeyViewModel)}}) Line 31 + 0xe bytes C#
  .ViewModels.CurveAreaViewModel.MoveSelectedItem(double deltaX = 82.0, double deltaY = -9.0) Line 126 + 0x63 bytes C#
  Views.CurveAreaView._AreaCanvas_MouseMove(object sender = {System.Windows.Controls.Canvas}, System.Windows.Input.MouseEventArgs e = {System.Windows.Input.MouseEventArgs}) Line 195 + 0x2d bytes C#

The question would be: Why could this happen, and what should I do to make it break at the Assert time?

I thought of using an exception, maybe for debugging, but it's really an assert that I need. I'm thinking about all my others Asserts also, without needing to always convert them to exceptions for debugging...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

子栖 2024-08-19 05:20:02

您可以通过编写自己的 TraceListener 在 AppDomain 范围内(如果您的应用程序只有一个 AppDomain,则在应用程序范围内)执行此操作。

首先创建一个包含 ExceptionTraceListener 类的类库项目 MyTraceListeners.dll

public class ExceptionTraceListener : TraceListener
{
  public override void Write(string message)
  {
    // Do nothing
  }
  public override void Fail(string message)
  {
    Debugger.Break();  // or if you prefer, throw new Exception(...)
  }
  public override void Fail(string message, string detailMessage)
  {
    Debugger.Break();  // or if you prefer, throw new Exception(...)
  }
}

现在您可以在应用程序的 .config< 中注册此 TraceListener /code> 文件以通常的方式:

<configuration>
  ...
  <system.diagnostics>
    ...
    <trace>
      <listeners>
        <clear />
        <add name="myListener" type="ExceptionTraceListener, MyTraceListeners" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

当您使用这些 .config 文件条目运行应用程序时,调试器将在每次断言失败时立即中断。

另请注意此配置文件中的 ,以清除 Machine.config 中列出的任何默认 TraceListeners。这很重要,因为默认的 TraceListener 将在您之前收到调用,并且仍然弹出 MessageBox

You can do this on a AppDomain-wide basis (Application-wide basis if your application has only one AppDomain) by writing your own TraceListener.

First create a class library project MyTraceListeners.dll containing an ExceptionTraceListener class:

public class ExceptionTraceListener : TraceListener
{
  public override void Write(string message)
  {
    // Do nothing
  }
  public override void Fail(string message)
  {
    Debugger.Break();  // or if you prefer, throw new Exception(...)
  }
  public override void Fail(string message, string detailMessage)
  {
    Debugger.Break();  // or if you prefer, throw new Exception(...)
  }
}

Now you can register this TraceListener in your application's .config file in the usual way:

<configuration>
  ...
  <system.diagnostics>
    ...
    <trace>
      <listeners>
        <clear />
        <add name="myListener" type="ExceptionTraceListener, MyTraceListeners" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

When you run your app with these .config file entries in place, the debugger will break immediately on every failed assertion.

Note also the <clear /> in this config file to clear any default TraceListeners listed in Machine.config. This is important because the default TraceListeners will receive the call before yours and still pop up the MessageBox.

念﹏祤嫣 2024-08-19 05:20:02

我以前见过类似的东西,当时有效的解决方法是添加一个 if 语句,其条件与断言相同,但被否定,并与调试器中在 if 的 then 块中的语句上设置的断点相结合。

I have seen something like this before, a workaround that worked at the time was to add an if statement with the same condition as the assert, but negated, combined with a breakpoint set in the debugger on a statement in the then block of the if.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文