2015-11-17 41 views
5

我記錄的堆棧跟蹤似乎缺少一個步驟。爲什麼我的堆棧跟蹤缺少步驟?

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,並且Build選項中的「優化代碼」處於未選中狀態。

+0

確保在調試選項中選中了「在模塊加載時抑制JIT優化」。 – leppie

回答

1

Dictionary<TKey, TValue>Add方法僅調用Insert,因爲它是一個1線方法,編譯器簡直是內聯方法調用,因爲它是那麼微不足道,即使沒有優化啓用。