【问题标题】:Getting an error trying to set conditional breakpoint using StackTrace尝试使用 StackTrace 设置条件断点时出错
【发布时间】:2021-06-02 02:23:21
【问题描述】:

我正在尝试使用此表达式设置条件断点:

new System.Diagnostics.StakTrace().ToString().Contains("SetupValidity")

但它总是出错:

The following breakpoint cannot be set:

(redacted) when 'new System.Diagnostics.StakTrace().ToString().Contains("SetupValidity")' is true

The condition for a breakpoint failed to execute. 
The condition was 'new System.Diagnostics.StakTrace().ToString().Contains("SetupValidity")'. 
The error returned was 'Evaluation of method System.Diagnostics.StackTrace.ToString requires calling method 
System.Reflection.MethodBase.get_MethodImplementationFlags, which cannot be called in this context.'

四处搜索,我发现了两个建议:

  • 检查(并重新启动 VS)Tools -> Options -> Debugging -> Use Managed Compatibility Mode
  • 检查(在项目属性中)Enable native code debugging

尝试分别同时启用这些功能.. 没有变化。

工具:

  • .NET Core 3.1
  • Microsoft Visual Studio Community 2019 16.8.5

我该如何解决这个问题?

【问题讨论】:

    标签: c# visual-studio debugging .net-core


    【解决方案1】:

    错误消息清楚地表明您无法“修复”此问题;如果您确实需要该中断条件,则需要更改代码,并在常规编译代码中评估 new System.Diagnostics.StakTrace().ToString(),然后执行您选择的任何测试/中断。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      相关资源
      最近更新 更多