2017-06-22 28 views
0

執行以下代碼時出現錯誤System.ArgumentException: An item with the same key has already been added相同的密鑰已經爲未知的時間間隔添加錯誤

問題是有時我會在程序啓動後1小時後出現此錯誤,有時會在5分鐘內出現。這取決於。

我試圖解釋所有細節,找不到原因。

public void getWE() 
    { 
     if (uceTopActivity.SelectedIndex == 0) 
     { 
      if (dtTopAll.AsEnumerable().Any() == true) 
      { 
       maxDate = dtTopAll.AsEnumerable().Max(z => z.Field<DateTime>("SAMPLE_TIME")); 
      } 

      var isFull = (dtTopAll.AsEnumerable().Where(l => l.Field<DateTime>("SAMPLE_TIME") == maxDate && l.Field<double>("WAITS") != 0)).Any(); 

      if (isFull == true) 
      { 
       var dt1 = (from dr1 in dtTopAll.AsEnumerable() 
          where dr1.Field<DateTime>("SAMPLE_TIME") == maxDate && dr1.Field<double>("WAITS") != 0 
          group dr1 by dr1.Field<string>("Event") into g 
          select new 
          { 
           Event = g.Key, 
           WAITS = g.Sum(z => z.Field<double>("WAITS")) 
          }).ToDataTable(); 

       ugWaitEvent.DataSource = dt1; 

       ugWaitEvent.DisplayLayout.Bands[0].Columns[1].Header.Caption = "Waits (ms/s)"; 
       ugWaitEvent.DisplayLayout.Bands[0].Columns[0].Width = 190; 
       ugWaitEvent.DisplayLayout.Bands[0].Columns[1].SortIndicator = SortIndicator.Descending; 
      } 
      else 
      { 
       ugWaitEvent.DataSource = null; 
      } 

     } 
    } 

這裏是錯誤的快照; Error

它有3個例外。我如何使用這些異常選項卡來獲取哪個函數以及哪個表單控件獲取錯誤;

Error: Translated - An item with the same key has already been added

然後,當我搜索字典中的單詞我得到下面對其Designer.cs線;

global::System.Collections.Generic.Dictionary<object, global::System.Data.IDbConnection> revertConnections = new global::System.Collections.Generic.Dictionary<object, global::System.Data.IDbConnection>(); 

global::System.Collections.Generic.IDictionary<global::System.Data.DataRow, global::System.Data.DataRow> traversedRows = new global::System.Collections.Generic.Dictionary<global::System.Data.DataRow, global::System.Data.DataRow>(); 
+1

哪一行引發異常?你確定**這是可能的行嗎? – mjwills

+0

@mjwills .net不顯示該行。只是拋出這樣的錯誤。 –

+0

@doctorcesar:你確定嗎?堆棧跟蹤說什麼?如果你調試它在哪裏破壞?非常罕見的是無法分辨出自己代碼中突破的行。 – Chris

回答

0

你有一些代碼有以下兩個變量之一交互:

global::System.Collections.Generic.Dictionary<object, global::System.Data.IDbConnection> revertConnections 

global::System.Collections.Generic.IDictionary<global::System.Data.DataRow, global::System.Data.DataRow> traversedRows 

該代碼嘗試添加相同的鍵不止一次。見https://stackoverflow.com/a/26516900/34092

+0

我不使用字典,控件自動添加到設計器中。 –

+0

您能否向我們展示設計人員的源代碼,以便我們協助解決? – mjwills

相關問題