当我尝试在 Visual Studio 中运行一些单元测试时,测试资源管理器会启动测试,然后我在测试资源管理器中收到以下错误指示符:
测试保持蓝色,既没有通过也没有失败,就像没有运行一样。
在我的输出窗口中,我收到以下错误:
Building Test Projects
========== Starting test run ==========
The active test run was aborted. Reason: Test host process crashed : Process is terminated due
to StackOverflowException.
Process is terminated due to StackOverflowException.
Process is terminated due to StackOverflowException.
========== Test run aborted: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in < 1 ms ==========
但是我在测试中看不到任何堆栈溢出的迹象。没有巨大的调用堆栈或内存峰值,这通常是一个指标。
我通过逐行调试得到了这段代码:
public async Task StopAsync(CancellationToken ct)
{
Logger.Information("Stopping consumers and workers...");
try
{
try
{
_cancellationTokenSource.Cancel();
}
catch (Exception ex)
{
Logger.Error(ex, "Exception during cancellation of the AJQ consumers / workers");
}
var timeout = _config.Bootstrapper.StopServiceTimeout;
Logger.Information($"Stop of worker/consumer tasks requested (waiting for: {timeout.TotalSeconds} sec for tasks to complete)");
var delayTask = Task.Delay(timeout, ct);
var waitAllTask = Task.WhenAll(AllTasks);
var tasks = new[] { delayTask, waitAllTask };
await Task.WhenAny(tasks).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.Error(ex, "Exception ... ");
}
}
在最后一行,当我按 F10 时,测试只是停止,没有错误,没有异常,什么也没有,它只是停止运行。
关于如何获得有关为什么会发生这种情况的更多信息,有什么见解吗?
我收到此错误,这是因为我的代码。这是因为,我在同一个类中为该类创建了一个对象(复制粘贴错误,从另一个类复制了对象),删除该对象及其引用为我解决了问题。
例如:在“Car”类中,我创建了“Car”对象并通过 Car.method 引用方法,通过删除“car”对象并直接调用方法解决了问题。