C# 同一密钥已添加未知时间间隔的错误
我收到错误C# 同一密钥已添加未知时间间隔的错误,c#,.net,linq,C#,.net,Linq,我收到错误System.ArgumentException:在执行以下代码时,已添加具有相同键的项 问题是,有时我会在程序启动后1小时内,有时在5分钟内,出现此错误。视情况而定 我试图解释所有细节,但找不到原因 public void getWE() { if (uceTopActivity.SelectedIndex == 0) { if (dtTopAll.AsEnumerable().Any() == true)
System.ArgumentException:在执行以下代码时,已添加具有相同键的项
问题是,有时我会在程序启动后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;
}
}
}
public void getWE()
{
如果(uceTopActivity.SelectedIndex==0)
{
if(dtTopAll.AsEnumerable().Any()==true)
{
maxDate=dtTopAll.AsEnumerable().Max(z=>z.Field(“采样时间”);
}
var isFull=(dtTopAll.AsEnumerable()。其中(l=>l.Field(“SAMPLE_TIME”)==maxDate&&l.Field(“WAITS”)!=0)。任意();
如果(isFull==true)
{
var dt1=(来自dtTopAll.AsEnumerable()中的dr1)
其中dr1.Field(“采样时间”)==maxDate&&dr1.Field(“等待”)!=0
按dr1.字段(“事件”)将dr1分组为g
选择新的
{
事件=g.键,
WAITS=g.Sum(z=>z.Field(“WAITS”))
}).ToDataTable();
ugWaitEvent.DataSource=dt1;
ugWaitEvent.DisplayLayout.Bands[0]。列[1]。标题。标题=“等待(毫秒/秒)”;
ugWaitEvent.DisplayLayout.Bands[0]。列[0]。宽度=190;
ugWaitEvent.DisplayLayout.Bands[0]。列[1]。SortIndicator=SortIndicator.Descending;
}
其他的
{
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>();
global::System.Collections.Generic.Dictionary revertConnections=new global::System.Collections.Generic.Dictionary();
global::System.Collections.Generic.IDictionary traversedRows=new global::System.Collections.Generic.Dictionary();
您的代码与以下两个变量之一交互:
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
global::System.Collections.Generic.Connections
全局::System.Collections.Generic.IDictionary traversedRows
该代码多次尝试添加同一密钥。请参阅。哪一行引发该异常?你确定这可能是一条线吗?@mjwills.net没有显示这条线。只是抛出一个这样的错误。@doctorcesar:你确定吗?堆栈跟踪显示了什么?如果调试它,它在哪里中断?在你自己的代码中,很难分辨出正在中断的那一行。@Chris我的意思是,它在program.cs中显示了这一行,而不是在上面的函数中。而program.cs只有一行“Application.Run(new Login());”@Chris在Question中添加了错误ss我不使用字典,控件会自动添加到设计器中。您能否向我们展示设计器的源代码,以便我们提供帮助?