[Mono-bugs] [Bug 61689][Wis] New - Can construct abstract class through reflection.
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Sat, 17 Jul 2004 14:22:13 -0400 (EDT)
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 cleonard@go.ro.
http://bugzilla.ximian.com/show_bug.cgi?id=61689
--- shadow/61689 2004-07-17 14:22:12.000000000 -0400
+++ shadow/61689.tmp.10697 2004-07-17 14:22:12.000000000 -0400
@@ -0,0 +1,86 @@
+Bug#: 61689
+Product: Mono: Class Libraries
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: cleonard@go.ro
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Can construct abstract class through reflection.
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+You can construct instances of abstract classes with reflection.
+
+Steps to reproduce the problem:
+Copy/paste this file, compile and execute.
+Just mcs test.cs; mono text.exe
+
+using System;
+using System.Reflection;
+
+abstract class SomeClass {
+ public SomeClass()
+ {
+ }
+
+ public abstract void DoSomething();
+}
+
+class Test {
+ static void Crash()
+ {
+ ConstructorInfo constructor;
+ SomeClass obj;
+
+ constructor = typeof(SomeClass).GetConstructor(Type.EmptyTypes);
+ Console.WriteLine("Got a Constructor Info");
+
+ obj = constructor.Invoke(null) as SomeClass;
+ Console.WriteLine("Created abstract class");
+
+ obj.DoSomething();
+ Console.WriteLine("Called abstract method");
+ }
+
+ static void Main()
+ {
+ try {
+ Crash();
+ } catch (Exception e) {
+ Console.WriteLine("Caught an exception: {0}", e.ToString());
+ }
+ }
+}
+
+
+Actual Results:
+Got a Constructor Info
+Created abstract class
+
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+
+Expected Results:
+Got a Constructor Info
+
+Caught an Exception: ....
+
+
+How often does this happen?
+Always.
+
+Additional Information:
+MSDN says that Invoke should throw an exception if you try to construct
+an abstract class. Mono crashes, but only at the actual method call.
+Here is the msdn doc:
+http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemReflectionConstructorInfoClassInvokeTopic2.asp