Page 1 of 1

Exception: An item with the same key has already been added

Posted: Mon 08 Mar 2010 11:52
by dilbert
We are still experiencing one indeterminate exception which occurs randomly with all kind of queries.

Here is a stacktrace:

Code: Select all

MESSAGE: An item with the same key has already been added.

STACKTRACE:    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Devart.Data.Linq.CompiledQueryCache.a(a A_0, CompiledQuery A_1)
   at Devart.Data.Linq.Provider.DataProvider.a(Expression A_0)
   at Devart.Data.Linq.Provider.DataProvider.h(Expression A_0)
   at Devart.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source)
   at ...
We use data context for atomic queries. Here is an example of the query which throws described exception:

Code: Select all

using (DBContext DB = new DBContext())
{
	return DB.Users.Where(u => u.Id == id).Single();
}

Unfortunately, I can't reproduce this problem. I only see a lot of these exceptions in our log file.

Can you advice any suggestion to fix this issue? (We are using the latest Mysql dotConnect beta version 5.70.102)

Thank you.

Posted: Tue 09 Mar 2010 16:07
by AndreyR
Thank you for the report, we will investigate this problem.
I will let you know about the results.

Posted: Fri 12 Mar 2010 10:08
by dilbert
I've sent you an email (Subject: Linq exceptions) with more specific information and detailed log file.

Just one more question. We need a workaround until source of the problem is found out. So is there any way how to reset compiled query cache (which probably causes the exception as I suppose according to exception stacktrace)?

Thank you.

Posted: Fri 12 Mar 2010 15:37
by AndreyR
Try just to comment out the CompiledQueryCache initialization in the template:

Code: Select all

//public static Devart.Data.Linq.CompiledQueryCache compiledQueryCache = Devart.Data.Linq.CompiledQueryCache.RegisterDataContext(typeof());

Posted: Fri 26 Nov 2010 11:24
by bmarotta
Do you have already a solution for this problem or should we still turn off the compiled query cache? What is the performance impact on it?

Posted: Fri 26 Nov 2010 17:40
by StanislavK
We couldn't reproduce this problem with LinqConnect Beta 2.0.7 (this is the version used in dotConnect for Oracle and dotConnect for MySQL 6.0.46).

Please specify whether you are encountering this problem with one of the latest versions of LinqConnect. If yes, what is the stack trace for the exception? Is it the same as dilbert[\b] has specified?

Posted: Tue 30 Nov 2010 11:19
by dilbert
Seeing activity in this thread I tried to enable query cache again after some time. After a few hours the application was down as before.

Here is an example of stack trace:

Code: Select all

MESSAGE: The LinkedList node does not belong to current LinkedList.
SOURCE: System
TARGETSITE: Void ValidateNode(System.Collections.Generic.LinkedListNode`1[T])
STACKTRACE:    at System.Collections.Generic.LinkedList`1.ValidateNode(LinkedListNode`1 node)
   at System.Collections.Generic.LinkedList`1.Remove(LinkedListNode`1 node)
   at Devart.Data.Linq.CompiledQueryCache.b(a A_0)
   at Devart.Data.Linq.Provider.DataProvider.BuildQuery(Expression query)
   at Devart.Data.Linq.Provider.DataProvider.Devart.Data.Linq.Provider.IProvider.Execute(Expression query)
   at Devart.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
...

Posted: Wed 01 Dec 2010 16:37
by StanislavK
Could you please describe the way you are working with data contexts in this application? Is it possible that one of them is being accessed from different threads?

If possible, please send us a test project with which the problem can be reproduced (at least occasionally).