none
Using Where clause of IQueryable with large amount of filters throws stack overflow exception RRS feed

  • Question

  • I have a big list of items in IQueryable object. When applying "where" clause to filter out values with around 300 filter values, it works fine. However, when the filter list (in the where clause) gets bigger (more than 300), the systems throw stack overflow exception at System.core.dll when I iterate through the list. 

    By the way, our system design doesn't use the database to filter out data since we need have the big data set in the cache.

    Please help. Thanks.

    Wednesday, September 25, 2013 4:15 AM

Answers

  • Hi Owen,

    The stack overflow exception is thrown when the execution stack overflows because it contains too many nested method calls. Please refer to the below reference to see the cause of this exception. http://www.dotnetperls.com/stackoverflowexception.

    I was surprised by the fact you have said “the systems throw stack overflow exception at System.core.dll when I iterate through the list”. I tried a large for loop, but my system does not throw this exception.

    Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default. Consequently, users are advised to write their code to detect and prevent a stack overflow. –MSDN

    See http://stackoverflow.com/questions/206820/how-do-i-prevent-and-or-handle-a-stackoverflowexception to know how to handler StackOverflowException.

    Hope useful to you.

    Best Regards,

    Hetro


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, September 26, 2013 7:13 AM
    Moderator