[Mono-dev] anonymous delegates, gmcs, and Microsoft.NET permissions checking problems

Avery Pennarun apenwarr at gmail.com
Thu Aug 23 17:26:19 EDT 2007


Hi all,

I'm using a copy of gmcs built on Linux from yesterday's mono svn
trunk.  The program listed below works fine when run under Linux, but
gives the following exception when run in Windows:

Unhandled Exception: System.MethodAccessException:
<>c__CompilerGenerated0.<Main>c__1()
   at MyClass.Main()

However, compiling it with Microsoft's csc.exe from .NET 2.0 results
in a binary that works in both Linux (mono) and Windows (.NET).

The command line I'm using to compile (under Cygwin) is:
   /c/WINDOWS/Microsoft.NET/Framework/v2.0.50727/csc.exe bug.cs
or in Linux:
   gmcs bug.cs

I also have gmcs (release) version 1.2.5.0 installed via
Ubuntu/dapper.  Compiling and running the binary with that version
works fine in both Linux and Windows.

Commenting out the two lines of code relating to the delegate in the
sample program also makes it work fine.  The crash occurs even if I
comment out the line calling the delegate (except I get an unused
variable warning, of course).

Thoughts?

Have fun,

Avery


using System;

public static class MyClass
{
    public delegate void Foo();

    public static void Main()
    {
	Console.WriteLine("hello");
	Foo x = delegate() {};
	x();
	Console.WriteLine("goodbye");
    }
}



More information about the Mono-devel-list mailing list