[Mono-bugs] [Bug 65933][Nor] Changed - No parameterless constructor defined by default with Reflection CreateType

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 4 Mar 2005 10:21:17 -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 martin.tapp@cae.com.

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

--- shadow/65933	2004-10-03 14:29:45.000000000 -0400
+++ shadow/65933.tmp.10878	2005-03-04 10:21:17.000000000 -0500
@@ -1,12 +1,12 @@
 Bug#: 65933
 Product: Mono: Class Libraries
 Version: unspecified
 OS: Red Hat 9.0
 OS Details: 
-Status: NEEDINFO   
+Status: REOPENED   
 Resolution: 
 Severity: 040 One week
 Priority: Normal
 Component: CORLIB
 AssignedTo: mono-bugs@ximian.com                            
 ReportedBy: martin.tapp@cae.com               
@@ -28,6 +28,46 @@
 Please provide a sample case, because I believe we do provide
 the default constructor as well (we know, because its broken, and
 we have to emulate it).
 
 Reopen the bug when you have a test case, am setting to NEEDINFO
 for now.
+
+------- Additional Comments From martin.tapp@cae.com  2005-03-04 10:21 -------
+Using Reflection:
+
+AssemblyName wAsmName = new AssemblyName();
+wAsmName.Name = "MyAssembly";
+
+string wPath = "/Some/Path";
+string wAssemblyDll = wPath + "/MyAssembly.dll";
+
+AssemblyBuilder wAsmBuilder = 
+AppDomain.CurrentDomain.DefineDynamicAssembly
+(wAsmName,AssemblyBuilderAccess.RunAndSave,wPath);
+
+ModuleBuilder wModuleBuilder = wAsmBuilder.DefineDynamicModule
+(wAssemblyDll,wAssemblyDll,false);
+
+TypeBuilder wTypeB1 = wModuleBuilder.DefineType
+("MyType1",TypeAttributes.Public|TypeAttributes.Class);
+// Need this line to get default constructor but not on windows
+//wTypeB1.DefineDefaultConstructor(MethodAttributes.Public);
+wTypeB1.CreateType();
+
+TypeBuilder wTypeB2 = wModuleBuilder.DefineType
+("MyType2",TypeAttributes.Public|TypeAttributes.Class,wTypeB1);
+// Need this line to get default constructor but not on windows
+//wTypeB2.DefineDefaultConstructor(MethodAttributes.Public);
+wTypeB2.CreateType();
+
+wAsmBuilder.Save(wAssemblyDll);
+
+Assembly wAssembly = AppDomain.CurrentDomain.Load
+(AssemblyName.GetAssemblyName(wAssemblyDll));
+
+Type wMyType2 = wAssembly.GetType("MyType2");
+
+// Next line throws since no default constructor
+object wInstance2 = Activator.CreateInstance(wMyType2);
+
+Martin