为什么我的堆栈跟踪丢失了步骤?

时间:2022-04-05 19:13:54

My logged stack trace seems to be missing a step.

我的日志堆栈跟踪似乎丢失了一个步骤。

private void StartLoadingResources(DataService separateDataService)
{
    ...
    batchResource.Resources.Add(key, new List<string>());
    // batchResource.Resources is the Dictionary object involved
    ...
}

Why has the stack trace gone straight from StartLoadingResources to Insert (missing the Add step)?

为什么堆栈跟踪直接从StartLoadingResources插入(缺少添加步骤)?

System.AggregateException: One or more errors occurred. ---> System.ArgumentException: An item with the same key has already been added.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at MyApp.Importer.StartLoadingResources(DataService separateDataService) in ****\MyApp\MyApp\Importer.cs:line 313
   at MyApp.Importer.<Execute>b__5() in ****\MyApp\MyApp\Importer.cs:line 142
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at MyApp.Importer.Execute() in ****\MyApp\MyApp\Importer.cs:line 157
   at MyApp.Program.Execute() in ****\MyApp\MyApp\Program.cs:line 252
   at MyApp.Program.Main(String[] args) in ****\MyApp\MyApp\Program.cs:line 47
---> (Inner Exception #0) System.ArgumentException: An item with the same key has already been added.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at MyApp.Importer.StartLoadingResources(DataService separateDataService) in ****\MyApp\MyApp\Importer.cs:line 313
   at MyApp.Importer.<Execute>b__5() in ****\MyApp\MyApp\Importer.cs:line 142
   at System.Threading.Tasks.Task.Execute()<---

The code is compiled as Debug, with "Optimize code" in Build options left unchecked.

代码被编译为Debug,在未检查的构建选项中保留“优化代码”。

1 个解决方案

#1


1  

The Add method on Dictionary<TKey, TValue> simply calls Insert, given that it's a 1 line method, the compiler has simply inlined that method call as it is so trivial even without optimizations enabled.

在Dictionary 只调用Insert,因为它是一个1行方法,编译器只是将该方法调用内联,因为即使不启用优化,它也非常简单。 上的add方法,tvalue>

#1


1  

The Add method on Dictionary<TKey, TValue> simply calls Insert, given that it's a 1 line method, the compiler has simply inlined that method call as it is so trivial even without optimizations enabled.

在Dictionary 只调用Insert,因为它是一个1行方法,编译器只是将该方法调用内联,因为即使不启用优化,它也非常简单。 上的add方法,tvalue>