How to kill the C# Compiler
My legendary skills in breaking code have now reached a new level, in which I managed to break the C# Compiler. Check out this code:
public delegate void Proc();
public class CrashAndBurnAttribute : System.Attribute
{
public CrashAndBurnAttribute(Proc p)
{ }
}
public class CrashAndBurnClient
{
[CrashAndBurn(delegate { return; })]
public void Foo()
{
}
}
If you try to run compile it from VS.Net you’ll get a nice crash dialog, and the result of running the compilation from the command line is:
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
crash.cs(11,16): error CS1706: Expression cannot contain anonymous methods
error CS0583: Internal Compiler Error (0xc0000005 at address 5A10A8E0): likely culprit is 'COMPILE'.
An internal error has occurred in the compiler. To work around this problem, try simplifying or changing the program near the locations listed below. Locations at the top of the list are closer to the point at which the internal error occurred. Errors such as this can be reported to Microsoft by using the /errorreport option.
crash.cs(11,25): error CS0585: Internal Compiler Error: stage 'COMPILE'
crash.cs(12,14): error CS0584: Internal Compiler Error: stage 'COMPILE' symbol 'CrashAndBurnClient.Foo()'
crash.cs(12,14): error CS0584: Internal Compiler Error: stage 'COMPILE' symbol 'CrashAndBurnClient.Foo()'
crash.cs(12,14): error CS0584: Internal Compiler Error: stage 'COMPILE' symbol 'CrashAndBurnClient.Foo()'
crash.cs(9,14): error CS0584: Internal Compiler Error: stage 'COMPILE' symbol 'CrashAndBurnClient'
crash.cs: error CS0584: Internal Compiler Error: stage 'COMPILE' symbol '<global namespace>'
crash.cs: error CS0586: Internal Compiler Error: stage 'COMPILE'
error CS0587: Internal Compiler Error: stage 'COMPILE'
error CS0587: Internal Compiler Error: stage 'BEGIN'
This is actually sad, since I really wanted to be able to do pass delegates to attributes.
Comments
Comment preview