[Mono-dev] Problem when embedding dll (without Main method)

holgers hschmalle at afmg.eu
Mon Oct 12 07:56:22 EDT 2009


Hello,

when embedding a dll which has no main method I encountered the following
problem:

I cannot invoke mono_jit_exec(...) because there is no main. This results in
a not completely initialized runtime.

Is there another way to initialize the runtime correctly?

The problem can easily be reproduced by applying the following patches to
the mono/samples/embed examples.

Compiled with:
gmcs invoke_mod.cs
gcc -Wall -o test-invoke_mod test-invoke_mod.c `pkg-config --cflags --libs
mono` -lm

Result:
./test-invoke_mod invoke_mod.exe In ctor val is: 5
In ctor str is: hello
Value of field is: 5
Value of str is: hello
In method val is 10
In method str is: hello from the embedding API

Unhandled Exception: System.TypeInitializationException: An exception was
thrown by the type initializer for System.Xml.Serialization.XmlSerializer
---> System.Configuration.ConfigurationErrorsException: Error Initializing
the configuration system. ---> System.NullReferenceException: Object
reference not set to an instance of an object
  at System.Configuration.ConfigurationManager.OpenExeConfigurationInternal
(ConfigurationUserLevel userLevel, System.Reflection.Assembly
calling_assembly, System.String exePath) [0x00000] 
  at System.Configuration.ClientConfigurationSystem.get_Configuration ()
[0x00000] 
  --- End of inner exception stack trace ---
  at System.Configuration.ClientConfigurationSystem.get_Configuration ()
[0x00000] 
  at
System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection
(System.String configKey) [0x00000] 
  at System.Configuration.ConfigurationManager.GetSection (System.String
sectionName) [0x00000] 
  at System.Configuration.ConfigurationSettings.GetConfig (System.String
sectionName) [0x00000] 
  at System.Xml.Serialization.XmlSerializer..cctor () [0x00000] 
  --- End of inner exception stack trace ---
  at Embed.MyType.method () [0x00000] 

Patches:

invoke_mod.cs:
--- invoke.cs	2009-10-12 13:21:13.000000000 +0200
+++ invoke_mod.cs	2009-10-12 13:36:28.000000000 +0200
@@ -1,6 +1,12 @@
 using System;
+using System.Xml.Serialization;
 
 namespace Embed {
+
+	public class Foo {
+		public int i;
+	}
+
 	class MyType {
 		int val = 5;
 		string str = "hello";
@@ -17,6 +23,7 @@
 		void method () {
 			Console.WriteLine ("In method val is {0}", val);
 			Console.WriteLine ("In method str is: {0}", str);
+			XmlSerializer ser = new XmlSerializer(typeof(Foo));
 		}
 
 		int Value {

test-invoke_mod.c:
--- test-invoke.c	2009-10-12 13:21:13.000000000 +0200
+++ test-invoke_mod.c	2009-10-12 13:19:53.000000000 +0200
@@ -307,7 +307,7 @@
 	 * The return value needs to be looked up from
 	 * System.Environment.ExitCode.
 	 */
-	mono_jit_exec (domain, assembly, argc, argv);
+	//mono_jit_exec (domain, assembly, argc, argv);
 
 	create_object (domain, mono_assembly_get_image (assembly));
 }

Regards,
Holger
-- 
View this message in context: http://www.nabble.com/Problem-when-embedding-dll-%28without-Main-method%29-tp25854471p25854471.html
Sent from the Mono - Dev mailing list archive at Nabble.com.



More information about the Mono-devel-list mailing list