[Mono-bugs] [Bug 36545][Nor] New - Embedding: Invoking a constructor fails
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Thu, 9 Jan 2003 16:25:06 -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 alp@atoker.com.
http://bugzilla.ximian.com/show_bug.cgi?id=36545
--- shadow/36545 Thu Jan 9 16:25:06 2003
+++ shadow/36545.tmp.16014 Thu Jan 9 16:25:06 2003
@@ -0,0 +1,91 @@
+Bug#: 36545
+Product: Mono/Runtime
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: misc
+AssignedTo: lupus@ximian.com
+ReportedBy: alp@atoker.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Embedding: Invoking a constructor fails
+
+Attempting to invoke the .ctor method of a class using mono_runtime_invoke
+fails. In the provided test case, invoking a static method in the class
+works, but invoking the constructor does not:
+
+$ mcs --target library Test.cs
+$ gcc `pkg-config --cflags --libs glib-2.0 mono` -lpthread test.c -o test
+$ ./test
+static c# method
+** (process:6326): WARNING **: Exception insinde function without unwind info
+** ERROR **: file exception.c: line 850 (arch_handle_exception): should not
+be reached
+aborting...
+Trace/breakpoint trap
+
+
+
+Test.cs:
+
+namespace Demo
+{
+ using System;
+
+ public class Test
+ {
+ public Test ()
+ {
+ Console.WriteLine ("ctor");
+ }
+
+ public static void StatMethod ()
+ {
+ Console.WriteLine ("static c# method");
+ }
+ }
+}
+
+test.c:
+
+#include <glib.h>
+#include <mono/metadata/object.h>
+
+int main () {
+
+ typedef struct MonoMethodDesc MonoMethodDesc;
+ MonoDomain *domain;
+ MonoAssembly *assembly;
+ MonoClass *test_class;
+ MonoMethodDesc *desc;
+ MonoMethod *meth;
+
+ domain = mono_jit_init ("demo");
+ assembly = mono_domain_assembly_open (domain, "Test.dll");
+ if (!assembly) g_error ("bad assembly: %s", "Test.dll");
+
+ test_class = mono_class_from_name (assembly->image, "Demo", "Test");
+ mono_class_init (test_class);
+
+ //invoke static method - it works
+ desc = mono_method_desc_new (":StatMethod()", 0);
+ if (desc == 0) g_error ("no such desc");
+ meth = mono_method_desc_search_in_class (desc, test_class);
+ if (meth == 0) g_error ("no such meth");
+ mono_runtime_invoke (meth, 0, 0, 0);
+
+ //invoke constructor - it fails
+ desc = mono_method_desc_new (":.ctor()", 0);
+ if (desc == 0) g_error ("no such desc");
+ meth = mono_method_desc_search_in_class (desc, test_class);
+ if (meth == 0) g_error ("no such meth");
+ mono_runtime_invoke (meth, 0, 0, 0);
+
+ return 0;
+}