Item has already been added. Key in dictionary: 'Int32 Count[Object](System.Collecti:ons.Generic.IEnumerable`1[System.Object])' Key being added: 'Int32 Count[Object](System.Collections.Generic.IEnumerable`1[System.Object])']
System.Reflection.CerHashtable`2.Insert(K[] keys, V[] values, Int32& count, K key, V value) +7473762
Error Page:
Server Error in '/Admin' Application.
Item has already been added. Key in dictionary: 'Int32 Count[Object](System.Collections.Generic.IEnumerable`1[System.Object])' Key being added: 'Int32 Count[Object](System.Collections.Generic.IEnumerable`1[System.Object])'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.ArgumentException: Item has already been added. Key in dictionary: 'Int32 Count[Object](System.Collections.Generic.IEnumerable`1[System.Object])' Key being added: 'Int32 Count[Object](System.Collections.Generic.IEnumerable`1[System.Object])'
Source Error:
Line 119: select q).ToList(); */
Line 120:
Line 121: var Result = (idc.EventLocations.Join(idc.Cities, el => el.CityId, c => c.ID, (el, c) => new { el.id, StartDate = el.StartDate, el.RegClosingDate, el.EndDate, el.CountryId, el.EventId, el.CityId, CityName = c.Name }).Join(idc.Countries, eloc => eloc.CountryId, con => con.Id, (eloc, con) => new { eloc.id, eloc.CountryId, eloc.EventId, eloc.RegClosingDate, eloc.EndDate, eloc.StartDate, eloc.CityId, eloc.CityName, CountryName = con.Name })).Join(idc.Events, elocc => elocc.EventId, EvenId => EvenId.Id, (elocc, EvenId) => new { elocc.id, elocc.StartDate, elocc.EndDate, elocc.RegClosingDate, elocc.EventId, elocc.CityName, elocc.CountryName, EvenId.Picture }).Where(a => a.EventId == Convert.ToInt64(eventid)).OrderBy(b => b.RegClosingDate).ToList();
Line 122:
Line 123: int cnt = Result.Count();
Source File: d:\IDCC\Website\IDCCircle\Admin\Events\EventDescription.aspx.cs Line: 121
Stack Trace:
[ArgumentException: Item has already been added. Key in dictionary: 'Int32 Count[Object](System.Collections.Generic.IEnumerable`1[System.Object])' Key being added: 'Int32 Count[Object](System.Collections.Generic.IEnumerable`1[System.Object])']
System.Reflection.CerHashtable`2.Insert(K[] keys, V[] values, Int32& count, K key, V value) +7473762
System.Reflection.CerHashtable`2.Preallocate(Int32 count) +301
System.RuntimeTypeCache.GetGenericMethodInfo(RuntimeMethodHandle genericMethod) +240
System.RuntimeType.GetMethodBase(RuntimeTypeHandle reflectedTypeHandle, RuntimeMethodHandle methodHandle) +438
System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation) +320
System.Linq.Queryable.Join(IQueryable`1 outer, IEnumerable`1 inner, Expression`1 outerKeySelector, Expression`1 innerKeySelector, Expression`1 resultSelector) +301
Events_EventDescription.bindLocations() in d:\IDCC\Website\IDCCircle\Admin\Events\EventDescription.aspx.cs:121
Events_EventDescription.Page_Load(Object sender, EventArgs e) in d:\IDCC\Website\IDCCircle\Admin\Events\EventDescription.aspx.cs:53
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Version Information: Microsoft .NET Framework Version:2.0.50727.5456; ASP.NET Version:2.0.50727.5456
VulpesPosted Nov 2, 2012, 2:54 PM
When adding new key/value pairs to the Dictionary, it's therefore best to check first whether the key already exists (using the ContainsKey method) to avoid getting this exception.