On Mon, 2009-03-23 at 21:15 +0100, Robert Jordan wrote:
> Chenthill wrote:
> > I updated to the last mono builds using monocharge and still see the 
> > problem.
> > Am loading the assembly from a library. So am not using mono_jit_exec..
> 
> You must use mono_jit_exec. Otherwise the runtime does not have
> sane defaults for the main assembly, which leads to errors whenever 
> Assembly.GetExecutingAssembly() is invoked.
> 
> Just add this code to the aforementioned assembly:
> 
> internal class EntryPoint {static void Main () {} }
> 
> and call mono_jit_exec on it before starting to use it. The assembly
> does not need to be an .exe.
I tried adding the EntryPoint class and compiling the assembly as a
library, but it did not work. I get the following error,

'Assembly 'sample.dll' doesn't have an entry point.'

Attaching the test programs which I used. Please change the hard coded
paths.

But compiling it as a executable seems to work fine!! I have changed my
code to have it as a workaround. Am really happy to get it working and
thanks a lot for your help :)


thanks, Chenthill.

> 
> Robert
> 
> _______________________________________________
> Mono-devel-list mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
#include <glib.h>
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>


void 
chen_go ()
{
	g_print ("Lets see how it goes \n");
}

int 
main (int argc, char *argv[])
{
	MonoDomain *domain;
	MonoAssembly *assembly;
	MonoImage *image;
	MonoMethod *method;
	MonoClass *mclass, *mclass1;
	MonoMethodDesc *desc;
	MonoObject *result, *this, *obool;
	void *args [1];
	gboolean val;
	

	domain = mono_jit_init ("/home/chen/practice/sample.dll");
	mono_thread_attach (domain);
	mono_config_parse (NULL);

	assembly = mono_domain_assembly_open (domain, "/home/chen/practice/sample.dll");
	if (!assembly) {
		g_print ("Opening assembly failed :( \n)");
		return 0;
	}
	mono_jit_exec (domain, assembly, argc -1, argv + 1);

/*	
	image = mono_assembly_get_image (assembly);
	desc = mono_method_desc_new ("test", FALSE);
	mclass = mono_class_from_name (image, "Myspace", "simple");
	mclass1 = mono_class_get_parent (mclass);
	if (mclass1)
	{
		g_print ("Got the parent class \n");
	} else {
		g_print ("No parent \n");
		return;
	}

	gpointer iter = NULL;

	while (method = mono_class_get_methods (mclass1, &iter)) {
		g_print ("\n Method name is : %s  \n", mono_method_get_name (method));
	}

	val = FALSE;
	args [0] = &val;

	method = mono_class_get_method_from_name (mclass1, "CallMe", -1);
	if (!method) {
		g_print ("Unable to get the method :( \n)");
		return 0;
	}
	this = mono_object_new (domain, mclass);
	mono_runtime_object_init (this);
	result = mono_runtime_invoke (method, this, NULL, NULL); */

	return 0;	
}
// sample.cs created with MonoDevelop
// User: chen at 3:28 PMĀ 6/21/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using System.Runtime.InteropServices;

namespace Myspace 
{		
	public class sample
	{
		[DllImport ("/home/chen/practice/mload", EntryPoint="chen_go")]
		static extern void chen_go ();

		[DllImport ("libc", EntryPoint="socket")]
		protected static extern int socket (int domain, int type, int protocol);
		
		public sample()
		{
			Console.Out.WriteLine ("I need to call this function from C now \n");
		}

		public void Chen ()
		{
			throw new Exception ("chen ");
			
		}

		public void Print ()
		{
			Console.WriteLine ("Print called");
		}

		public void CallMe () 
		{
			string chen = "No value passed";
			int r = socket (1, 1, 0);

			try {
				Chen ();
			} catch (Exception ex)
			{
				Console.WriteLine (ex.Message);

			}

			Console.Out.WriteLine (chen);
		}

//		public static void Main ()
//		{
//			sample chen = new sample ();
//				
//			chen.CallMe ();
//
//			chen_go ();
//		}
	
	
	}

	public class simple:sample
	{
		public void derived ()
		{
			
		}
	}

	internal class EntryPoint 
	{
		public static void Main () {} 
	}
}
_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to