gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:44:30 25 4
gpt4 key购买 nike

我记录的堆栈跟踪似乎缺少一个步骤。

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,未选中构建选项中的“优化代码”。

最佳答案

Add Dictionary<TKey, TValue> 上的方法只需调用 Insert ,鉴于它是一个 1 行方法,编译器简单地内联了该方法调用,因为即使没有启用优化,它也是如此微不足道。

关于c# - 为什么我的堆栈跟踪缺少步骤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com