[Mono-bugs] [Bug 75512][Blo] New - execution-time problem with initialization of static enum array

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Jul 8 22:05:53 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by ash at onezero.org.

http://bugzilla.ximian.com/show_bug.cgi?id=75512

--- shadow/75512	2005-07-08 22:05:53.000000000 -0400
+++ shadow/75512.tmp.25479	2005-07-08 22:05:53.000000000 -0400
@@ -0,0 +1,64 @@
+Bug#: 75512
+Product: Mono: Runtime
+Version: 1.1
+OS: Windows XP (Cygwin)
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: misc
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: ash at onezero.org               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: execution-time problem with initialization of static enum array
+
+Howdy.  It looks like I have found a pretty bad bug involving static 
+initialization of arrays with enumeration values.  I have pared the 
+example down from a large program that I have developed in .NET and am 
+trying out in mono; the 20 lines or so here is the smallest I can get it 
+without deleting more and having the problem go away.  It runs fine 
+with .NET 2.0 beta.  I am using mcs version 1.1.7.0 and mono version 
+1.1.7.1.  The following code compiles fine and gives the exception (shown 
+after the code) when executed:
+
+using System;
+
+class EnumTest {
+  public enum EE
+  {
+      A = 0
+    , B = 1
+    , C = 2
+    , D = 3
+  }
+
+  public static void Main()
+  {
+    Console.WriteLine("s_arr[0] = {0}", s_arr[0]);
+  }
+
+  static EE[] s_arr = {
+      EE.A
+    , EE.B
+    , EE.C
+    , EE.D
+  };
+}
+
+Unhandled Exception: System.TypeInitializationException: The type 
+initializer for "EnumTest" threw an exception. ---> 
+System.ArgumentException: Value does not fall within the expected range.
+   at System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(Array 
+array, RuntimeFieldHandle fldHandle)
+   at EnumTest..cctor()
+   --- End of inner exception stack trace ---
+   at EnumTest.Main()
+Unknown signal 79
+
+When the array definition is moved inside the method and the word "static" 
+is removed from the definition, the code compiles and runs fine.  
+Removing "D" and its reference also makes the code run fine.


More information about the mono-bugs mailing list