[Mono-bugs] [Bug 42883][Nor] New - Assembly.CreateInstance donn't work as in MS.NET
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Tue, 13 May 2003 08:47:27 -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 roboto@gmx.net.
http://bugzilla.ximian.com/show_bug.cgi?id=42883
--- shadow/42883 Tue May 13 08:47:27 2003
+++ shadow/42883.tmp.24930 Tue May 13 08:47:27 2003
@@ -0,0 +1,97 @@
+Bug#: 42883
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Mandrake 9.1
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: roboto@gmx.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Assembly.CreateInstance donn't work as in MS.NET
+
+Description of Problem:
+Assembly.CreateInstance(string className) throws a
+'System.TypeLoadException' if the class isn't found.
+On .NET 1.0 (can't test it with 1.1) it returns simply null
+
+Steps to reproduce the problem:
+1. compile the code bellow
+2. running the exe
+
+Actual Results:
+<output>
+I'm the constructor!
+ConsoleApplication.MyTest
+
+Unhandled Exception: System.TypeLoadException: A type load exception has
+occured.
+in (unmanaged)
+/usr/local/mono_05.05.2003/lib/libmono.so.0(mono_raise_exception+0x20)
+[0x40087325]
+in (unmanaged) /usr/local/mono_05.05.2003/lib/libmono.so.0 [0x4008d55e]
+in <0x00052> 00 System.Reflection.Assembly:GetType (string,bool,bool)
+in <0x00025> 00 System.Reflection.Assembly:CreateInstance (string,bool)
+in <0x00019> 00 System.Reflection.Assembly:CreateInstance (string)
+in <0x0007e> 00 ConsoleApplication.Class1:Main (string[])
+</output>
+
+Expected Results:
+I'm the constructor!
+ConsoleApplication.MyTest
+Null
+
+Additional Information:
+<code>
+using System;
+using System.Reflection;
+
+namespace ConsoleApplication
+{
+ class Class1
+ {
+ [STAThread]
+ static void Main(string[] args)
+ {
+
+ //this works as expected since the cllass exists
+ object newInstance =
+Assembly.GetCallingAssembly().CreateInstance("ConsoleApplication.MyTest");
+ if ( newInstance == null) {
+ Console.WriteLine("Null");
+ }
+ else {
+ Console.WriteLine(newInstance.GetType());
+ }
+
+ //this throws a 'System.TypeLoadException'. but under .NET 1.0
+newInstance2 is null.
+ object newInstance2 =
+Assembly.GetCallingAssembly().CreateInstance("ConsoleApplication.Foo");
+ if ( newInstance2 == null) {
+ Console.WriteLine("Null");
+ }
+ else {
+ Console.WriteLine(newInstance2.GetType());
+ }
+
+ }
+ }
+
+ public class MyTest
+ {
+
+ public MyTest()
+ {
+ Console.WriteLine("I'm the constructor!");
+ }
+ }
+
+}
+</code>