Rider调试ASP.NET Core时报thread not gc-safe的解决方法

新建了一个ASP.NET Core 5.0的Web API项目,当使用断点调试Host.CreateDefaultBuilder(args)时,进入该函数后查看中间变量的值,报错Evaluation is not allowed: The thread is not at a GC-safe point。在群里问了也没人回应,可能没有遇到过这个问题吧。

一.解决问题的过程

1.Visual Studio 2022调试

  首先想到的是可能Rider不行,换成Visual Studio 2022试试,所以就查到了文献[1],发现需要pdb文件,还需要设置符号什么的,觉得太麻烦了。

2.Rider调试

  然后又换成了Rider,既然调试看不到中间变量的值,那就直接Console.WriteLine()出来,结果Console在当前上下文中根本就不存在,如下:

二.最终的解决方法

1.YouTrack上的解决方法

  继续在网上查找,发现在JetBrains的官方YouTrack上[2][3],Evgeny Terekhin在2022年5月30日给出了一个解决方法:

SET COMPLUS_ZapDisable=1	NGen off (CLR)
SET COMPLUS_JitMinOpts=1	Disable as much JIT optimizations as possible (CoreCLR)
SET COMPlus_TieredCompilation=0	No tiered JIT, only do one pass (CoreCLR)
SET COMPLUS_ReadyToRun=0	Don't do netcore's analog to NGen (CoreCLR)

大概的意思是对CLR做了设置,先不管设置的什么了,抱着试试看的心态。配置launchSettings.json文件:

"environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development",
    "COMPLUS_ZapDisable": "1",
    "COMPLUS_JitMinOpts": "1",
    "COMPlus_TieredCompilation": "0",
    "COMPLUS_ReadyToRun": "0"
}

完成的配置文件如下所示:

2.调试ASP.NET Core

  打上断点启动调试后,神奇般的发现也可以查看中间变量了。如下:

Rider调试源码还是比Visual Studio方便很多,不需要pdb文件,也不需要设置什么符号,只需要进入要调试的函数中打上断点,然后启动调试即可。

参考文献:
[1]Debugging External Sources with Visual Studio:https://devblogs.microsoft.com/visualstudio/debugging-external-sources-with-visual-studio/
[2]Debugger: Evaluation is not allowed: The thread is not at a GC-safe point:https://youtrack.jetbrains.com/issue/RIDER-40357
[3]When debugging, variables don't display all of their data, instead we get 'Evaluation is not allowed: The thread is not at a GC-safe point':https://youtrack.jetbrains.com/issue/RIDER-10885/When-debugging-variables-dont-display-all-of-their-data-instead-we-get-Evaluation-is-not-allowed-The-thread-is-not-at-a-GC-safe

 

转 https://www.cnblogs.com/shengshengwang/p/16573520.html

posted @   dreamw  阅读(78)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2021-08-25 最详细之教你Jenkins+github自动化部署.Net Core程序到Docker
2021-08-25 mysql中的on的执行顺序_MySQL -- join , on , where 的执行顺序
2021-08-25 【知识】MySQL索引原理及慢查询优化
2021-08-25 【MySQL优化】——看懂explain
2021-08-25 SourceTree拉取代码和自己本地代码冲突解决方案,git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin解决
2021-08-25 MySQL索引原理以及查询优化
2021-08-25 MySQL索引原理及慢查询优化
点击右上角即可分享
微信分享提示