mishrsud / mvc-mini-profiler

Automatically exported from code.google.com/p/mvc-mini-profiler
0 stars 0 forks source link

Problems explicitly disposing of a IDataReader after closing it. #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
We have code to close a dispose of a IDataReader like this:

    try
    {
        if (!dr.IsClosed)
        {
            dr.Close();
        }
    }
    finally
    {
        dr.Dispose();
    }

However it throws an exception:
[KeyNotFoundException: The given key was not present in the dictionary.]
   System.Collections.Generic.Dictionary`2.get_Item(TKey key) +78
   MvcMiniProfiler.SqlProfiler.ReaderFinishedImpl(DbDataReader reader) in C:\Dev\mvc-mini-profiler\MvcMiniProfiler\SqlProfiler.cs:69
   MvcMiniProfiler.SqlProfilerExtensions.ReaderFinish(SqlProfiler sqlProfiler, DbDataReader reader) in C:\Dev\mvc-mini-profiler\MvcMiniProfiler\SqlProfiler.cs:103
   MvcMiniProfiler.Data.ProfiledDbDataReader.Close() in C:\Dev\mvc-mini-profiler\MvcMiniProfiler\Data\ProfiledDbDataReader.cs:71
   System.Data.Common.DbDataReader.Dispose(Boolean disposing) +44
   System.Data.Common.DbDataReader.Dispose() +36

I'm guessing that this is because ReaderFinish has been called twice and the 
2nd time the reader isn't in the Dictionary any more.

Original issue reported on code.google.com by keithhe...@gmail.com on 10 Jun 2011 at 2:49

GoogleCodeExporter commented 8 years ago
Your analysis is correct, it was double-handled in your case.

There's now a check for this in the dictionary fetch added just now in 
changeset 
http://code.google.com/p/mvc-mini-profiler/source/detail?r=eacf85b3ea53eec0d299c
c32119b4f5dfeb5dd79

You can grab the latest and should be good to go.

Original comment by nrcraver on 10 Jun 2011 at 11:57