visual-studio-2010 - 如何进入TargetInitationException?

标签 visual-studio-2010 debugging dispatcher targetinvocationexception

我收到像这样的 TargetInitationExceptions

An unhandled exception of type System.Reflection.TargetInvocationException occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.

因为我正在使用

调用代码
Dispatcher.Invoke(MyRoutine...)

如何让 VS 2010 调试器单步进入 MyRoutine 到异常实际发生的位置???

我知道我可以围绕 Dispatcher.Invoke 构建一个 try...catch,然后查看内部异常,但这非常费力。我希望调试器在错误发生的地方停止。

有什么想法可以做到这一点吗?

最佳答案

Dispatcher.Invoke() 将设置一个 catch block ,以便它可以将任何异常编码(marshal)回调用它的线程。以便调用者知道 Invoke() 返回值不可用。此 catch block 可防止调试器在抛出异常时自动中断。原始异常作为 TargetInitationException 对象的 InnerException 传递。这可能足以诊断原因。

请考虑使用 BeginInvoke(),它不需要执行这种编码(marshal)处理,因为调用它的代码不再事件。它也不太容易出现死锁。

但是如果您确实需要返回值,那么只有 Invoke() 可以提供它。调试异常的方法是使用 Debug + Exceptions 并勾选 CLR 异常的 Thrown 复选框。当抛出异常时,这会强制调试器停止。

关于visual-studio-2010 - 如何进入TargetInitationException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16279829/

相关文章:

C++ - 在 Visual Studio 2010 的属性表中使用环境变量

c# - 在 Visual C# 中,如何禁用 WiX 项目? (使构建太慢)

c++ - Mudflap 不合理地报告内存访问冲突

java - 如何在netbeans、java web项目的第一行中断

wpf - "The calling thread must be STA"解决方法

c# - 如何在 Nunit 中调用 WPF Dispatcher?

vb.net - 编写 Dispatcher.Invoke VB.NET

visual-studio-2010 - 错误只发生在 Release模式

visual-studio-2010 - Visual Studio : Remove all break points in visual studio 2010 express

debugging - 记录二进制文件的行为?