[Mono-dev] Embedding w/ Config Errors | No Entry Assembly

Robert Jordan robertj at gmx.net
Mon Sep 7 06:38:03 EDT 2009


Matthew Metnetsky wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> All,
> 
> As some might have picked up I'm embedding Mono into a project and all
> is mostly going well. While trying to tie together .NET objects with
> GObject's via compiled MonoMethod thunks I hit a snag.
> 
> 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
> 
> After digging through a bit it looks like the static .ctor of
> XmlSerializer calls ConfigurationSettings.GetConfig which triggers a
> chain of methods getting called to find the configuration for the
> Assembly.GetEntryAssembly().
> 
> Sadly the entry assembly is NULL so the whole system goes BOOM! Mono is
> embedded so that I can instantiate classes and then some methods from C.
> As there is no EXE how can I properly LIE to the framework so it'll
> believe there is one?
> 
> Finally, I'm initializing the runtime like so:
> 
>   mono_config_parse(NULL);
>   domain = mono_jit_init_version("Blox", "v2.0.50727");
> 
> And then calling mono_domain_assembly_open(domain, "Other.dll")
> each time I load a new DLL.
> 
> I've tried mono_jit_init("../to/some/actual/dll") and that failed too.
> 
> Thoughts/suggestions anyone?

Add an entry point to your assembly:

class EntryPoint { static void Main () {} }

Then compile the assembly with "/target:exe" (you can rename it to .dll
after the compilation).

Then call mono_jit_exec () somewhere after mono_jit_init ()
and before calling other methods. See main_function () in
one of Mono's embedding samples:

http://anonsvn.mono-project.com/viewvc/trunk/mono/samples/embed/teste.c?view=markup

Please file a bug if it still doesn't work.

Robert



More information about the Mono-devel-list mailing list