为什么我的堆栈跟踪缺少步骤?

6

我的堆栈跟踪似乎缺少一步。

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

为什么堆栈跟踪直接从StartLoadingResourcesInsert了(缺少Add步骤)?
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()<---

代码以 Debug 模式编译,构建选项中的“优化代码”未被勾选。

请确保在调试选项中勾选了“模块加载时抑制JIT优化”。 - leppie
1个回答

1

Dictionary<TKey, TValue> 上的 Add 方法只是简单地调用 Insert 方法,因为它只有一行代码,即使没有启用优化,编译器也会将该方法调用内联,因为它非常简单。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接