System.InvalidOperationException: Handle is not initialized

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
nlundberg
Posts: 3
Joined: Wed 07 Oct 2009 21:23

System.InvalidOperationException: Handle is not initialized

Post by nlundberg » Mon 02 Nov 2009 15:38

This exception occured when I ran an ASP.NET Application with WebDev.WebServer.exe. It was performing multiple insert statements.

An unhandled exception occurred and the process was terminated.
Application ID: c0fb25be
Process ID: 952
Exception: System.InvalidOperationException
Message: Handle is not initialized.

StackTrace: at System.Runtime.InteropServices.GCHandle.get_Target()
at Devart.Data.Linq.o.i()
at Devart.Data.Linq.d.a(Int32 A_0)
at Devart.Data.Linq.y.a(a A_0)
at Devart.Data.Linq.y.a.b()

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

Post by AndreyR » Mon 02 Nov 2009 16:37

Please specify what dotConnect and of which version you are using.

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

Post by dilbert » Thu 18 Mar 2010 11:17

Today our application was down for a few minutes. In Windows Aplicataion Event Log is this exception. We are using the latest beta version of dotConnect for Mysql (5.70.102.0).
After this error IIS recycled the application.

Code: Select all

An unhandled exception occurred and the process was terminated.
Exception: System.InvalidOperationException

Message: Handle is not initialized.

StackTrace:    at System.Runtime.InteropServices.GCHandle.get_Target()
   at Devart.Data.Linq.c.i()
   at Devart.Data.Linq.g.a(Int32 A_0)
   at Devart.Data.Linq.e.a(a A_0)
   at Devart.Data.Linq.e.a.b()

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

Post by AndreyR » Fri 19 Mar 2010 11:49

The only possible reason we can conclude from our code is multithreading issue.
Please make sure you are using one DataContext object per thread.

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

Post by dilbert » Mon 22 Mar 2010 15:16

I have sent you sample application via email (subject: linq problems) with our typicall using of datacontext.

I would appreciate any suggestion.
Thank you.

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

Post by AndreyR » Thu 25 Mar 2010 12:56

We have replied to your mail.

EricDahlvang
Posts: 4
Joined: Wed 21 Jul 2010 15:51

We are also experiencing this exception

Post by EricDahlvang » Wed 21 Jul 2010 23:28

07/20/2010 16:58:55 Unhandled Exception:

Code: Select all

System.InvalidOperationException: Handle is not initialized. 
07/20/2010 16:58:55 	   at System.Runtime.InteropServices.GCHandle.get_Target() 
07/20/2010 16:58:55 	   at Devart.Data.Linq.c.i() 
07/20/2010 16:58:55 	   at Devart.Data.Linq.g.a(Int32 A_0) 
07/20/2010 16:58:55 	   at Devart.Data.Linq.e.a(a A_0) 
07/20/2010 16:58:55 	   at Devart.Data.Linq.e.a.b() 
This exception occurs within the execution path of a single thread. The answer provided by AndreyR is "Make sure you are using one DataContext object per thread" In our current code, we create a data context at the beginning of an operation, and dispose of it when we commit the transaction. We create and destroy multiple data contexts for the duration of the operation. However, we only have one active data context on a thread at any given time, and a thread only ever uses that one data context.

We have spent a significant amount of time attempting to track this down. Any assistance would be greatly appreciated.

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

Post by AndreyR » Fri 23 Jul 2010 11:09

We have not reproduced this error. We have deobfuscated the call stack, the most likely
cause of the problem is the multithreading issue.
That would be great if you are capable of making a small test project reproducing the problem.

Post Reply