Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:31:19+00:00 2026-06-09T15:31:19+00:00

I’m having a really hard time debugging some LINQ to SQL code because there

  • 0

I’m having a really hard time debugging some LINQ to SQL code because there is no call stack and I have no idea where the error is occurring. It doesn’t seem to be a SQL error – it’s in C#, but through searching around and everything else, I can’t find any way to figure out which calculation is giving the error.

The source code is below and you can see the error that is thrown when I try to insert some new rows. The call stack is empty and the exception contains no information about what went wrong.

var groups =
    from record in startTimes
    group record by record.startTime
    into g
    select new
               {                                   
                   startTime = g.Key.GetValueOrDefault(),
                   totalTasks = g.Count(),
                   totalTime = g.Max(o => o.record.timeInSession).GetValueOrDefault(),
                   minDwell = g.Min(o => o.record.dwellTime).GetValueOrDefault(),
                   maxDwell = g.Max(o => o.record.dwellTime).GetValueOrDefault(),
                   avgDwell = g.Average(o => o.record.dwellTime).GetValueOrDefault(),
                   stdevDwell = g.Select(o => Convert.ToDouble(o.record.dwellTime)).StdDev(),
                   correct80 = g.Sum( o => o.record.correct80.GetValueOrDefault() ? 1 : 0),
                   wrong80 = g.Sum(o => o.record.wrong80.GetValueOrDefault() ? 1 : 0)
               };

var statistics = groups.AsEnumerable().Select(
    g => new e_activeSession()
             {
                 workerId = wcopy,
                 startTime = g.startTime,
                 totalTasks = g.totalTasks,
                 totalTime = g.totalTime,
                 minDwell = g.minDwell,
                 maxDwell = g.maxDwell,
                 avgDwell = g.avgDwell,
                 stdevDwell = g.stdevDwell,
                 total80 = g.correct80 + g.wrong80,
                 correct80 = g.correct80,
                 percent80 = g.correct80 / (g.correct80 + g.wrong80)                                 
             }
    );                                       

// Put these rows into the table                
_gzClasses.e_activeSessions.InsertAllOnSubmit(statistics);                
_gzClasses.SubmitChanges();

Call stack and generally unhelpful exception

Here’s the stack trace for the exception. If anyone can decipher it, please tell me, because I have no clue how to read these anonymous types…

at System.Data.SqlClient.SqlBuffer.get_Double()
at System.Data.SqlClient.SqlDataReader.GetDouble(Int32 i)
at Read_<>f__AnonymousType2`9(ObjectMaterializer`1 )
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Data.Linq.Table`1.InsertAllOnSubmit[TSubEntity](IEnumerable`1 entities)

Also, I’ve run this query in LINQPad and got the same error and stack trace. Finally, here’s the database query generated by LINQ to SQL that was executed right before the error. I don’t see any double conversions in it at all.

SELECT COALESCE([t5].[value22],'1/1/0001 12:00:00 AM') AS [startTime], [t5].[value] AS [totalTasks], COALESCE([t5].[value2],0) AS [totalTime], COALESCE([t5].[value3],0) AS [minDwell], COALESCE([t5].[value4],0) AS [maxDwell], COALESCE([t5].[value5],0) AS [avgDwell], [t5].[value6] AS [correct80], [t5].[value7] AS [wrong80], [t5].[value22]
FROM (
    SELECT COUNT(*) AS [value], MAX([t4].[timeInSession]) AS [value2], MIN([t4].[dwellTime]) AS [value3], MAX([t4].[dwellTime]) AS [value4], AVG([t4].[dwellTime]) AS [value5], SUM([t4].[value3]) AS [value6], SUM([t4].[value]) AS [value7], [t4].[value2] AS [value22]
    FROM (
        SELECT 
            (CASE 
                WHEN (COALESCE([t3].[wrong80],0)) = 1 THEN @p4
                ELSE @p5
            END) AS [value], [t3].[workerID], [t3].[value2], [t3].[timeInSession], [t3].[dwellTime], [t3].[value] AS [value3]
        FROM (
            SELECT 
                (CASE 
                    WHEN (COALESCE([t2].[correct80],0)) = 1 THEN @p2
                    ELSE @p3
                END) AS [value], [t2].[wrong80], [t2].[workerID], [t2].[value] AS [value2], [t2].[timeInSession], [t2].[dwellTime]
            FROM (
                SELECT (
                    SELECT MAX([t1].[timeStamp])
                    FROM [dbo].[workerLog] AS [t1]
                    WHERE ([t1].[dwellTime] IS NULL) AND ([t1].[timeInSession] = @p0) AND ([t1].[workerID] = @p1) AND ([t1].[timeStamp] <= [t0].[timeStamp])
                    ) AS [value], [t0].[workerID], [t0].[dwellTime], [t0].[timeInSession], [t0].[correct80], [t0].[wrong80]
                FROM [dbo].[workerLog] AS [t0]
                ) AS [t2]
            ) AS [t3]
        ) AS [t4]
    WHERE [t4].[workerID] = @p6
    GROUP BY [t4].[value2]
    ) AS [t5]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:31:20+00:00Added an answer on June 9, 2026 at 3:31 pm

    Let’s read that call stack:

    at System.Data.SqlClient.SqlBuffer.get_Double() 
    at System.Data.SqlClient.SqlDataReader.GetDouble(Int32 i) 
    at Read_<>f__AnonymousType2`9(ObjectMaterializer`1 ) 
    at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() 
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() 
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
    at System.Data.Linq.Table`1.InsertAllOnSubmit[TSubEntity](IEnumerable`1 entities) 
    

    InsertAllOnSubmit is the top of the stack. It called ToList, which called List’s “ctor” which means constructor.

    That List constructor enumerates its parameter (a deferred query), causing the query to be resolved.

    During the enumeration in the List constructor, we try to move to the next element in the query (WhereSelectEnumerableIterator.MoveNext) – this is an enumerator created by your call to Select after AsEnumerable. In order to move to the new element, what we actually need to do is drill deeper into the query (ObjectReader.MoveNext), which is going to create some object from the database results.


    At this point, I’d like to point out that you didn’t say the type for startTimes. I’m guessing startTimes is a LinqToSql query


    So, that database query was turned into a DataReader (not captured on the stack), and we are extracting a row from the DataReader (Read_<>f__AnonymousType29(ObjectMaterializer1 )) so we can turn that row into the .net instance that is the result of the query.

    In the process of extracting values from the row, there’s a double value involved, so we try to extract that (.GetDouble(Int32 i) and .get_Double()), . Now, we know that a DataReader can think of its values as an object[] (reference SqlDataReader.GetValues). It seems reasonable that GetDouble might be implemented something like this:

    //rubbish implementation, the point is - a cast from object to double is made
    public double GetDouble(Int32 i)     {
      double result = (double) this.GetValues()[i];
      return result;
    }
    

    So, the object in the data reader’s array doesn’t cast to double. The most likely posibility is that the object is null!

    It is also remotely possible that some other type is present (string or byte[] or whatever), but if you used LinqToSql’s designer to make a dbml file, and the tables in the database still agree with that dbml, this is unlikely.


    I see that Convert.ToDouble is not in the call stack. This must have been done before – in the database. Convert.ToDouble is -never actually called-… instead it is translated to sql and run there. The rules for type conversion are different in the database.

    • If you try to convert null to a double in .net, you get an exception.
    • If you try to convert null to a double in sql, you get a null.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.