最近我的 IDE 在调试时表现异常 - 每当我尝试进入异步方法 (C#) 时,调试会话立即结束。像这样:
我的问题: 我还能做些什么来调查/排除故障,任何人都可以深入了解可能发生的事情吗?
更多细节,我尝试过的等等。
我首先在 AspNetCore 应用程序中注意到这一点,但它可以在简单的控制台应用程序中重现,如 GIF 中一样。这是我用来重现它的代码。
Console.WriteLine("Start");
// Can step into fine
Hello();
// Step into immediately crashes program
await HelloAsync();
Console.WriteLine("End");
void Hello() {
Console.Write("Hello sync");
}
async Task HelloAsync() {
await Task.Delay(100);
Console.Write("Hello async");
}
这是我目前所知道的:
我使用的是 M1 Macbook Pro,所以不确定这是否与某些 ARM 初期问题有关。
这是我尝试过的:
我也将向 Jetbrains 发布错误报告,但同时我想尝试自己进一步深入研究,因为感觉像是 Rider 和我的系统(/我的 dotnet 安装)之间的问题,这可能是我特有的。
骑手日志的相关部分
07:04:14.312 |V| RiderDebuggerSessionFrontend | ClientSocket-DebuggerWorkerToFrontend-Receiver:13 | Debugger command received from frontend: StepIntoActionModel ()
07:04:14.371 |I| CorRuntimeEventProcessor | Debugger worker MTA main thread:6 | Target process exited
07:04:14.372 |V| RiderDebuggerSessionFrontend | Debugger worker MTA main thread:6 | Event from debugger: type TargetExited
07:04:14.372 |V| RiderDebuggerWorker | Debugger worker MTA main thread:6 | Firing target exited to frontend
调试器断开连接——这可能是正常的行为,因为调试器实际上并没有崩溃:
05:46:51.427 |V| Client | ClientSocket-DebuggerWorkerHost::10-Receiver:72 | ClientSocket-DebuggerWorkerHost::10 Connection was gracefully shutdown
05:46:51.427 |V| Client | ClientSocket-DebuggerWorkerHost::10-Receiver:72 | ClientSocket-DebuggerWorkerHost::10: Total traffic: sent 690, received 4436
05:46:51.427 |V| ClientSocket-DebuggerWorkerHost::10-Sender| ClientSocket-DebuggerWorkerHost::10-Receiver:72 | PAUSE ('Disconnected') :: state=AsyncProcessing
05:46:51.427 |V| Client | ClientSocket-DebuggerWorkerHost::10-Receiver:72 | ClientSocket-DebuggerWorkerHost::10: connecting to 127.0.0.1:51839.
05:46:51.427 |V| Client | ClientSocket-DebuggerWorkerHost::10-Receiver:72 | ClientSocket-DebuggerWorkerHost::10: connection error for endpoint "127.0.0.1:51839". Connection refused 127.0.0.1:51839
--- EXCEPTION #1/2 [ExtendedSocketException]
Message = “Connection refused”
ExceptionPath = Root.InnerException
ClassName = System.Net.Internals.SocketExceptionFactory+ExtendedSocketException
HResult = E_FAIL=EFail=80004005
Source = System.Net.Sockets
NativeErrorCode = 61
StackTraceString = “
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) in DoConnect.il:line IL_007C mvid A973
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP) in Connect.il:line IL_00E6 mvid A973
at JetBrains.Rd.Impl.SocketWire.Client.<>c__DisplayClass1_0.<.ctor>b__0() in Client.il:line IL_0069 mvid E45C
”
--- Outer ---
--- EXCEPTION #2/2 [LoggerException]
Message = “ClientSocket-DebuggerWorkerHost::10: connection error for endpoint "127.0.0.1:51839". Connection refused 127.0.0.1:51839”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
InnerException = “Exception #1 at Root.InnerException”
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
at JetBrains.Util.LoggerBase.Log(LoggingLevel level, String message, Exception ex) in Log.il:line IL_0024 mvid A7F4
at JetBrains.Diagnostics.LogEx.Verbose(ILog this, Exception ex, String message) in Verbose.il:line IL_0000 mvid 89A1 or Verbose.il:line IL_0008 mvid 89A1
at JetBrains.Diagnostics.LogEx.Verbose(ILog logger, Exception ex, JetLogVerboseInterpolatedStringHandler& messageHandler) in Verbose.il:line IL_0000 mvid 89A1 or Verbose.il:line IL_0008 mvid 89A1
at JetBrains.Rd.Impl.SocketWire.Client.<>c__DisplayClass1_0.<.ctor>b__0() in Client.il:line IL_0069 mvid E45C
at System.Threading.Thread.StartHelper.Callback(Object state) in Callback.il:line IL_0000 mvid 5DC4
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid 5DC4
”
使用系统崩溃日志中的关键字我终于能够找到相关问题的网络。
主要有两个:
看起来这是 ARM Mac 上的 dotnet 问题。
目前,有两种解决方法。
启用 dotnet 调试器的“Just My Code”功能。
在 Jetbrains Rider 中,这是通过 Enable external source debug
下的
disabling
Settings > Build, Execution, Deployment > Debugger
来完成的:
调试程序时添加
DOTNET_ReadyToRun=0
作为环境变量。
请注意,显然这并非在所有情况下都有效,因此有时您可能不得不使用解决方法#1。