当前位置:网站首页>Rider调试ASP.NET Core时报thread not gc-safe的解决方法
Rider调试ASP.NET Core时报thread not gc-safe的解决方法
2022-08-10 20:31:00 【阿升】
新建了一个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
边栏推荐
猜你喜欢
随机推荐
MySQL查询数据库中的表和字段
详叙c中的分支与循环
echart 特例-多分组X轴
设备管理中数据聚类处理
[Golang]从0到1写一个web服务(上)
Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
TortoiseSVN小乌龟的使用
金鱼哥RHCA回忆录:CL210OpenStack操作的故障排除--章节实验
[SemiDrive source code analysis] [MailBox inter-core communication] 52 - DCF Notify implementation principle analysis and code combat
Knowledge map Knowledge Graph
leetcode:45. 跳跃游戏II
如何提高代码的可读性 学习笔记
2021年中国工业互联网安全大赛(福建省选拔赛) 暨首届福建省工业互联网创新大赛
Web3中值得关注的基础设施
重载和重写
链表应用----约瑟夫问题
.NET现代应用的产品设计 - DDD实践
Heme - gold nanoparticles (Heme - AuNP) composite nanometer enzyme | gold nanoparticles nuclear porous hollow carbon nanometer spherical shell (Au @ HCNs) nano enzyme
机器学习模型验证:被低估的重要一环
leetcode 85.最大矩形 单调栈应用





![[SWPUCTF 2021 新生赛] web](/img/e9/07e7db7ddf8328589a078e98fd46ad.png)



