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

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
dilbert
Posts: 68
Joined: Tue 28 Apr 2009 10:11

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

Post by dilbert » Mon 08 Mar 2010 11:52

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 09 Mar 2010 16:07

Thank you for the report, we will investigate this problem.
I will let you know about the results.

dilbert
Posts: 68
Joined: Tue 28 Apr 2009 10:11

Post by dilbert » Fri 12 Mar 2010 10:08

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 12 Mar 2010 15:37

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());

bmarotta
Posts: 34
Joined: Wed 29 Sep 2010 11:27

Post by bmarotta » Fri 26 Nov 2010 11:24

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?

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 26 Nov 2010 17:40

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?

dilbert
Posts: 68
Joined: Tue 28 Apr 2009 10:11

Post by dilbert » Tue 30 Nov 2010 11:19

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)
...

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 01 Dec 2010 16:37

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).

Post Reply