我收到像这样的 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/