2015-11-17 3 views
5

В моей записи стека стека, кажется, отсутствует шаг.Почему мой стек отслеживает недостающие шаги?

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

Почему трассировка стека ушел прямо из StartLoadingResources в Insert (отсутствующего в 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()<--- 

Код скомпилирован как «Отладка» с «Оптимизировать код» в параметрах Build, которые не были сняты.

+0

Убедитесь, что параметр «Подавление оптимизации JIT при загрузке модуля» отмечен в параметрах «Отладка». – leppie

ответ

1

Способ по Dictionary<TKey, TValue>Add просто вызывает Insert, учитывая, что это метод 1 линии, компилятор просто встраиваемый этот вызов метода, как это так тривиально, даже без оптимизации включена.

Смежные вопросы