Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Linq Min() crashes Visual Studio

I have a piece of code that makes the Visual Studio 2008 IDE run very slow, consume vast amounts of memory and then eventually causes it to crash. I suspect VS is hitting an OS memory limit.

The following code is not my real application code, but it simulates the problem. Essentially I am trying to find the minimum value within a tree using LINQ.

class LinqTest
{
    public class test
    {
        public int val;
        public List<test> Tests;
    }

    private void CrashMe()
    {
        test t = new test();

        //Uncomment this to cause the problem
        //var x = t.Tests.Min(c => c.Tests.Min(d => d.Tests.Min(e => e.Tests.Min(f=>f.Tests.Min(g=>g.Tests.Min(h => h.val))))));
    }
}

Has anyone else seen something similar?

like image 556
eyesnz Avatar asked Jul 21 '09 23:07

eyesnz


2 Answers

A while ago I submitted a bug report on MS Connect. This morning I got a response:

Thanks for the bug report for Visual Studio 2008!

As you point out in your linked post from Eric Lippert's blog, we have limits on our ability to do type inference on such nested lambda expressions in a reasonable amount of time. That said, we could certainly try to timebox such inference or put a hard limit on lambda nesting to prevent this type of issue. Unfortunately, we're starting to lock down on what we can fix in Visual Studio 2010 and we won't be able to enforce such limits in this release.

We'll definitely keep this issue in mind when planning for future releases!

Alex Turner

Program Manager

Visual C# Compiler

and

The following feedback item you submitted at Microsoft Connect has been updated: Product/Technology - Visual Studio and .NET Framework - Feedback ID – 476133 Feedback Title – Nested Linq Min() crashes Visual Studio 2008 IDE The following fields or values changed: Field Status changed from [Active] to [Resolved]

Field Resolution changed from [None] to [Won't Fix]

like image 180
geofftnz Avatar answered Oct 16 '22 14:10

geofftnz


I was able to repro this on my Visual Studio 2008 install. It looks like the language service is hitting an infinite loop and eventually running out of memory. Can you please file a bug on the connect site?

Connect: http://connect.microsoft.com

If you do file the bug, please add a comment to my answer with the bug number.

like image 36
JaredPar Avatar answered Oct 16 '22 14:10

JaredPar