執行以下代碼時出現錯誤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;
}
}
}
它有3個例外。我如何使用這些異常選項卡來獲取哪個函數以及哪個表單控件獲取錯誤;
然後,當我搜索字典中的單詞我得到下面對其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>();
哪一行引發異常?你確定**這是可能的行嗎? – mjwills
@mjwills .net不顯示該行。只是拋出這樣的錯誤。 –
@doctorcesar:你確定嗎?堆棧跟蹤說什麼?如果你調試它在哪裏破壞?非常罕見的是無法分辨出自己代碼中突破的行。 – Chris