[Mono-dev] Embedding Mono

Duane Wandless duane at wandless.net
Tue Mar 15 07:35:16 EDT 2011

If you saw the example code I sent I was passing the full path to the EXE to
both mono_jit_init and mono_domain_assembly_open.

The purpose of embedding is to embed the Mono runtime into your app so that
it runs without installing Mono.  This error  indicates the embedded runtime
could not find the MonoPosixHelper dll or dylib.  When running mono from the
terminal you have the fully installed mono runtime so everything resolved.

In my code before calling mono_jit_init I do this:

NSString *mPath = [[[NSBundle mainBundle] bundlePath]

mono_assembly_setrootdir([mPath UTF8String]);

Then I have the folder structure:

I have all DLLs my app depends on.  For example, System.Configuration.dll,
System.dll, System.Core.dll, Mono.Posix.dll, etc.  As well as my DLLs.

Your app may also depend on:

So you have to include that file in the Libraries folder as well as link
against it so that it loads at runtime.  You can also manually call dlopen
passing the "correct" path to libMonoPosixHelper.dylib.  Correct
being relative or full, though I recommend full.

I do not know how you are compiling your OSX app but otool and
install_name_tool were very useful in my understanding of the embedding

There are also older threads on the mono mailing lists that have more
details.  You can do a google search to find them "mono embed osx duane".

Hope that helps you move along.

On Tue, Mar 15, 2011 at 6:45 AM, vinay_rk <vinay.kashyap at ironmountain.com>wrote:

> Hi,
> I got the thing to work... but I' am not very thrilled with the
> resolution... It seems like it'll work only if I use the same string for
> both MonoDomain creation thru mono_jit_init and also for loading assembly
> thru mono_domain_assembly_open.. In essense I am having to pass the
> assembly
> file path string even for the Domain, I used to think that it just requires
> a string name for the domain.
> But with this issue gone.. when I continued my work I hit upon another
> issue: My managed app uses the Mono.Unix.UnixDirectoryInfo class and at the
> instantiation of this class I get an exception that says :
> Unhandled Exception: System.TypeInitializationException: An exception was
> thrown by the type initializer for Mono.Unix.Native.Syscall --->
> System.DllNotFoundException: MonoPosixHelper
>  at (wrapper managed-to-native) Mono.Unix.Native.Syscall:_L_ctermid ()
>  at Mono.Unix.Native.Syscall..cctor () [0x00000] in :0
>  --- End of inner exception stack trace ---
>  at Mono.Unix.UnixFileSystemInfo.GetFileStatus (System.String path,
> Mono.Unix.Native.Stat& stat) [0x00000] in :0
>  at Mono.Unix.UnixFileSystemInfo.Refresh (Boolean force) [0x00000] in :0
>  at Mono.Unix.UnixFileSystemInfo..ctor (System.String path) [0x00000] in :0
>  at Mono.Unix.UnixDirectoryInfo..ctor (System.String path) [0x00000] in :0
>  at SimpleScanner.Program.Main (System.String[] args) [0x00000] in :0
> I am trying this on Mac OSX and I dont get this problem if I run my exe
> directly from Terminal using:  Mono . So how is the environment different
> in
> case of Mono Embedding for this to happen.
> Any help is highly appreciated...
> Thanks in advance.
> -Vinay
> --
> View this message in context:
> http://mono.1490590.n4.nabble.com/Embedding-Mono-tp3345310p3356206.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110315/cbf7939d/attachment-0001.html 

More information about the Mono-devel-list mailing list