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

2024-05-07

我有一个 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#
  

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

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


您可以通过编写自己的应用程序域范围(如果您的应用程序只有一个应用程序域,则为应用程序范围的基础)来执行此操作TraceListener.

首先创建一个类库项目MyTraceListeners.dll含有一个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(...)
  }
}

现在您可以注册这个TraceListener在你的应用程序中.config按照通常的方式归档:

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

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

另请注意<clear />在此配置文件中清除任何默认值TraceListeners列于Machine.config。这很重要,因为默认TraceListeners 将在您之前接到电话,并且仍然弹出MessageBox.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Trace.Assert 没有中断,也不显示消息框 的相关文章

随机推荐

  • 第 n 个孩子没有响应课程 [重复]

    这个问题在这里已经有答案了 是否可以让 nth child 伪选择器与特定的类一起使用 看这个例子 http jsfiddle net fZGvH http jsfiddle net fZGvH 我想让第二个 DIV red 变成红色 但它
  • HttpServletRequest.getRemotePort() 在同一台机器上收到的每个 http 请求返回不同的端口?

    我需要识别注册到我的服务的客户端的远程 IP 和端口 此外 当客户端 Web 应用程序出现故障时 它会从我的 Web 服务中取消注册 我在用HttpServletRequest getRemoteAddress and HttpServle
  • 如何在C#中确定现有的oracle数据库连接?

    假设我使用正确的凭据调用以下方法 private bool Connect string username string password string CONNSTRING Provider MSDAORA Data Source ISD
  • Single.zip - 如何捕获失败的呼叫并继续其余的网络呼叫?

    我正在进行 5 个并行网络调用 模拟其中 4 个成功 其中 1 个失败 失败的调用使整个Single zip 失败 即使其他 4 个网络调用成功 我也无法获得它们的结果 如何处理单个失败的网络调用的错误Single zip 并获得成功者的结
  • 标头搜索路径给 Grabkit 带来麻烦

    我正在为 iPad 开发一个 iOS 6 应用程序 我使用一个名为 Grabkit 的存储库 我必须将其作为嵌套 子项目添加到我的项目中 为了使其工作 我必须在标题搜索路径中添加以下代码 TARGET BUILD DIR include G
  • 按行中的值选择 pandas 数据框中的列

    我有一个pandas DataFrame列太多 我想选择行中的值等于的所有列0 and 1 所有列的类型是int64我无法通过以下方式选择它们object或其他类型 我怎样才能做到这一点 IIUC 然后你可以使用isin http pand
  • Javascript:使用箭头键导航表格输入

    我正在为客户制作 HTML 成绩册 我使用 PHP 生成成绩册 然后输出一个 HTML 表 如下例所示 每个 td 包含一个带有 td
  • Spring 3 JSR-286(portlet)文档

    我知道Spring 3支持JSR 286 portlet 版本 2 0 但是我找不到很多这方面的文档 任何人都可以分享一些关于此的链接吗 谢谢 找到几个教程 使用 Spring 3 MVC Portlet 的 Hello World htt
  • 配置解析器和带 % 的字符串

    愚蠢的问题 当然 简单的答案 我正在使用 configparser 从文件中读取一些字符串 当字符串具有 符号 例如 时 它会抱怨 ConfigParser InterpolationSyntaxError 后必须跟 或 找到 有人熟悉这个
  • 防止打开 VB 应用程序的多个实例

    我的 VB6 应用程序由 MS Access 数据库支持 允许用户打开应用程序的多个实例会产生冲突并更改连接的数据库 理想的解决方案是 如果用户尝试打开新实例 则关注现有实例 我怎样才能达到这个目的 Use App PrevInstance
  • Spark 中的广播 Annoy 对象(对于最近邻居)?

    由于 Spark 的 mllib 没有最近邻居功能 我正在尝试使用Annoy https github com spotify annoy为近似最近邻 我尝试广播 Annoy 对象并将其传递给工人 然而 它并没有按预期运行 下面是可重复性的
  • 删除重载、递归溢出

    嘿伙计们 我写了一个快速测试 我想删除调用deleteMe 然后它会自行删除 这样做的目的是让我可以正常删除由lib分配的obj 我不希望因 crt 或 w e 导致任何崩溃 通过删除这个 我得到了一个堆栈溢出 没有它 msvc 说我泄漏了
  • 无法从 AsyncTask 启动服务

    我正在尝试从 AsyncTask 启动服务 但看不到它的启动 我还在清单文件中添加了服务 这里是代码 protected Integer doInBackground Void values throws InterruptedExcept
  • 使用 SAS 导出到 Excel

    假设我有 2 个 SAS 数据集 test1 sas 和 Test2 sas 现在我想将这2个数据集导出到Excel中 其中Excel文件Sheet1中将有test1 sas数据 Sheet2中将有test2 sas数据 怎么做 从 开始这
  • C++ 检查 unicode 字符是否为全角

    如何检查unicode字符是否是全角 我使用Win32 MFC 例如 中是全宽 A不是全角 是全宽 F不是全宽 你需要的是检索东亚宽度 http www unicode org reports tr11 的角色 您可以通过解析来做到这一点东
  • 关键词是真还是假?

    Are true and falseJava 中的关键字 这是完整的列表Java 语言关键字 http java sun com docs books tutorial java nutsandbolts keywords html 特别要
  • Javascript:确认、确定、取消按钮上的自定义文本

    我有一个验证 我想显示 继续 和 返回 而不是 确定 和 取消 但我无法找到准确的解决方案 任何人都可以帮助我
  • 嵌套列表递归python的序列

    给定一些数字 n 我想生成一个大小为 n 的列表 其中以下示例显示列表中的第 n 个元素应该如何 对于 n 0 返回 对于 n 1 返回 对于 n 2 返回 对于 n 3 返回 基本上 它采用先前的列表并将它们附加到新列表中 我尝试过以下方
  • com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:连接关闭后不允许执行任何操作

    我构建了一个应用程序并在本地部署 并且它运行良好 我将其部署在远程服务器上 并开始收到主题行中提到的异常 这不是因为任何防火墙问题 我改变了我的hibernate xml通过我的 IP 地址而不是 localhost 进行连接 现在我在本地
  • Trace.Assert 没有中断,也不显示消息框

    我有一个 WPF 应用程序 我在其中在画布上移动数据 当我像怪物一样尝试用鼠标移动数据时 问题就开始了 以下是操作的顺序 画布上的 MouseMove 被触发 在 MouseMove 中 我更改了一些数据 Trace Assert 失败 调