Solution 1:

Clearly that is a compiler bug.

I mentioned this to one of our testers and he says:

I’m happy to report that this has already been fixed and you’ll see this fix in the next version of VS. You’ll actually see it fixed in the BUILD Developer Preview for Visual Studio as well!

Apologies for the error, and thanks for bringing this to our attention.

Solution 2:

I reproduced the crash using VS2010 (WinXP 64).

Two workarounds:

1. don't use the using alias

The following code compiles cleanly on VS2010:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<dynamic, dynamic, dynamic> True = (a, b) => a;
            Func<dynamic, dynamic, dynamic> False = (a, b) => b;

            Func<Func<dynamic, dynamic, dynamic>, 
                 Func<dynamic, dynamic, dynamic>,
                 Func<dynamic, dynamic, dynamic> > And 
                = (x, y) => x(y(True, False), False);
        }
    }
}

2. use the Mono compiler

No problem with Mono 2.10 compiler (dmcs).

[mono] /tmp @ dmcs test.cs
test.cs(18,42): warning CS0219: The variable `And' is assigned but its value is never used
Compilation succeeded - 1 warning(s)
[mono] /tmp @ ./test.exe 
[mono] /tmp @ 

This was tested on linux.

  1. You can run binaries created with mono on Windows .NET.
  2. Mono compiler comes with an installer MSI and runs on Windows as well.

Solution 3:

EDIT: I've now managed to reproduce it, and I have a potential workaround.

This works:

csc Test.cs

This doesn't:

csc /debug+ Test.cs

So it looks like it's a problem with the debug information. If you can live without that in your particular scenario, you're good to go...

EDIT: I've just tested, and this happens with /debug:pdbonly as well...

EDIT: Just in case anyone was wondering, I'll ping Eric Lippert about this.

EDIT: This is now the minimal repro I've found:

using church = System.Func<dynamic>;

class Program
{
    static void Main() {}
}