[Mono-dev] Creating AppDomains From Embedded Mono

Robert Jordan robertj at gmx.net
Wed Jan 11 09:32:36 EST 2006

Hi Jim,

> Hi Robert/Everyone,
>>You can and *should* invoke the managed
>>AppDomain methods to load and unload domains. 
>>You don't need an intermediate managed assembly 
>>to do that (untested):
>>createDomain (char *name) ....
>>unloadDomain (MonoAppDomain *domain) ...
> That gets me a MonoAppDomain*, which I can presumably
> use to call AppDomain.Load(Byte[]) to load a script's
> assembly, which will be unloaded (along with JIT
> output etc.) when I call unloadDomain?

MonoAppDomain is the unmanaged representation of System.AppDomain.
You can call every System.AppDomain method using mono_runtime_invoke,
like in my sample above.

> How do I turn the MonoAppDomain in to a MonoDomain
> required by mono_object_new, mono_string_new etc.?

Indeed, there is no accessor defined for it, but you can
define this struct somewhere after you include appdomain.h:

struct _MonoAppDomain {
         MonoObject obj;
         MonoObject *identity;
         MonoDomain *data;

> That is what my intermediate managed assemblies were
> doing: executing an assembly in the new domain which
> would call mono_domain_get() to get me a MonoDomain*
> for the new MonoAppDomain.
> Do I even need a MonoDomain* for the new
> MonoAppDomain? At the moment I try to allocate any
> objects used by a script in the AppDomain that I
> loaded the script's assembly in to, but I suppose I
> could allocate the other objects in the root domain.
> Would there be any problems doing this? My concern
> would be that the root domain would end up loading the
> script's assembly which I then couldn't unload.

You have to use the proper MonoDomain.


More information about the Mono-devel-list mailing list