[Mono-bugs] [Bug 73136][Wis] New - Problem in static class initialization
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Mon, 28 Feb 2005 21:59:16 -0500 (EST)
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 spigaz@gmail.com.
http://bugzilla.ximian.com/show_bug.cgi?id=73136
--- shadow/73136 2005-02-28 21:59:16.000000000 -0500
+++ shadow/73136.tmp.32617 2005-02-28 21:59:16.000000000 -0500
@@ -0,0 +1,76 @@
+Bug#: 73136
+Product: Mono: Compilers
+Version: 1.1
+OS:
+OS Details: Gentoo 2.6.10
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: C#
+AssignedTo: martin@ximian.com
+ReportedBy: spigaz@gmail.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Problem in static class initialization
+
+Description of Problem:
+A static class doesn't intiale correctly its fields before its static
+methods are called.
+
+Steps to reproduce the problem:
+1. Insert into a file:
+ public class A
+ {
+ public void X()
+ {
+ System.Console.WriteLine("OK");
+ }
+ }
+ public static class B
+ {
+ protected static A _a = new A();
+
+ public static void X()
+ {
+ _a.X();
+ }
+ }
+ public class Test
+ {
+ public static void Main(string [] args)
+ {
+ B.X();
+ }
+ }
+2. Compile it normally with gmcs
+3. Execute it
+
+Actual Results:
+
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+in <0x0000b> FLMID.Bugs.StaticOne.B:X ()
+in <0x00007> FLMID.Bugs.StaticOne.Test:Main (System.String[] args)
+
+
+Expected Results:
+OK
+
+How often does this happen?
+Always
+
+Additional Information:
+It works fine on .Net 2.0 Beta1 and even the assembly from it works fine on
+mono. So its really a gmcs problem.
+
+Workarround:
+
+protected static A _a;
+
+static ControllerFactory()
+{
+ _a = new A();
+}