当前位置:网站首页>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
边栏推荐
- 每日一R「03」Borrow 语义与引用
- 2021 GKCTF X DASCTF应急挑战杯
- Auto.js找图找色常用功能
- 【ACM】dp专场训练
- 第四届红帽杯网络安全大赛
- @Autowired注解 --required a single bean, but 2 were found出现的原因以及解决方法
- Apple Font Lookup
- .NET现代应用的产品设计 - DDD实践
- 【nvm】【node多版本管理工具】使用说明和踩坑(exit status 1)
- Pt/CeO2 monatomic nanoparticles enzyme | H - rGO - Pt @ Pd NPs enzyme | carbon nanotube load platinum nanoparticles peptide modified nano enzyme | leukemia antagonism FeOPtPEG composite nano enzyme
猜你喜欢

Detailed explanation and use of each module of ansible

单选点击可取消功能

@Autowired annotation --required a single bean, but 2 were found causes and solutions

导入FontForge生成字体

Transferrin (TF) Modified Paclitaxel (PTX) Liposomes (TF-PTX-LP) | Transferrin (Tf) Modified Curcumin Liposomes

(十二) findContours函数的hierarchy详解

饿了么-机构树单选

(十二)STM32——NVIC中断优先级管理

【nvm】【node多版本管理工具】使用说明和踩坑(exit status 1)

The most complete GIS related software in history (CAD, FME, ArcGIS, ArcGISPro)
随机推荐
[Golang]用反射让你的代码变优美
(十二) findContours函数的hierarchy详解
Heme - gold nanoparticles (Heme - AuNP) composite nanometer enzyme | gold nanoparticles nuclear porous hollow carbon nanometer spherical shell (Au @ HCNs) nano enzyme
如何提交一个PR?【OpenHarmony成长计划】【OpenHarmony开源社区】
leetcode 547.省份数量 并查集
单选点击可取消功能
Redis命令手册
npm‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件
Web3中值得关注的基础设施
2021DASCTF实战精英夏令营暨DASCTF July X CBCTF 4th
[mysql] 深入分析MySQL版本控制MVCC规则
血红素-金纳米颗粒(Heme-AuNP)复合纳米酶|金纳米颗粒核多孔空心碳纳米球壳([email protected])纳米酶
多功能纳米酶Ag/PANI|柔性衬底纳米ZnO酶|铑片纳米酶|Ag-Rh合金纳米颗粒纳米酶|铱钌合金/氧化铱仿生纳米酶
双 TL431 级联振荡器
The most complete GIS related software in history (CAD, FME, ArcGIS, ArcGISPro)
2020 ICPC Shanghai Site G
三子棋的设计和代码
苹果字体查找
姜还是老的辣,看看老战哥的老底儿和严谨劲儿
工程师应该怎么学习