Unhandled exception from SqlCeDataReader.Finalize

Topics: Data Access Application Block
Nov 14, 2016 at 2:59 AM
Hello

I have a piece of code where we use SqlCeDatabase class as below
sqlCeDatabase.ExecuteResultSet(command, options, parameters);
If the command passed is an invalid one, we get an exception and we handle it with try-catch

But after some time an unhandled exception is thrown from SqlCeDataReader.Finalize() with following trace
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical">
<TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier>
<Description>Unhandled exception</Description>
<AppDomain>xxx.vshost.exe</AppDomain>
<Exception>
<ExceptionType>System.ArgumentNullException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Value cannot be null.</Message>
<StackTrace>   at System.Threading.Monitor.Enter(Object obj)
   at System.Data.SqlServerCe.SqlCeDataReader.Dispose(Boolean disposing)
   at System.Data.SqlServerCe.SqlCeDataReader.Finalize()</StackTrace>
<ExceptionString>System.ArgumentNullException: Value cannot be null.
   at System.Threading.Monitor.Enter(Object obj)
   at System.Data.SqlServerCe.SqlCeDataReader.Dispose(Boolean disposing)
   at System.Data.SqlServerCe.SqlCeDataReader.Finalize()</ExceptionString>
</Exception>
</TraceRecord>
If I comment out SqlCeDatabase.ExecuteResultSet, there is no unhandled exception.

Since the ExecuteResultSet call throws exception there is no SqlCEResultSet to dispose. I would like to know why the Finalize of DataReader is invoked, as the exception was thrown before the reader is initialized?