[Mono-dev] Initialization of array of enum - trying to not use RuntimeInternals.InitializeArray

Marek Safar marek.safar at gmail.com
Mon Jul 23 07:53:22 UTC 2012

Hello John,
> There is a known bug in the Microsoft CLR on the x86_64 platform with 
> regards to initializing an array whose members are enum values 
> (http://connect.microsoft.com/VisualStudio/feedback/details/635365/runtimehelpers-initializearray-fails-on-64b-framework). 
> It appears that the Microsoft csc compiler somehow works around this 
> whereas gmcs does not.  For example, the following compiled with gmcs 
> does not run on the Microsoft CLR on x86_64 (it throws an exception in 
> InitializeArray) but does when compiled with csc:
> class Program
> {
>   enum e { A, B, C, D, E };
>   static void Main()
>   {
>     e[] array = new e[] { e.A, e.B, e.C, e.D, e.E };
>   }
> }
> I appreciate this is apparently a bug with the Microsoft 64 bit CLR 
> rather than mono, but at the moment Microsoft's csc appears to work 
> around this where mono does not.  Is there a way of telling gmcs to 
> not use a call to InitializeArray when instantiating arrays of enums 
> (instead doing something like: e[] array = new e[5]; e[0] = e.A; e[1] 
> = e.B; ... for the above example), or if not would there be any 
> support for adding this (e.g. via an optional command line flag to gmcs)?
Expanding the initialization is the easiest option how to workaround 
this .net bug. Because the scope of the bug is quite limited and easy to 
workaround I don't think it's work adding special handling for it. 
Microsoft already fixed the issue but I am not sure whether there is a 
hotfix available for .NET 2.0


More information about the Mono-devel-list mailing list