[Mono-dev] Creating AppDomains From Embedded Mono

Jim Purbrick jimpurbrick at yahoo.co.uk
Wed Jan 11 15:23:11 EST 2006


Thanks Zoltan, 

I've got it working on Linux too and it used to work
on Windows until my hard drive died and I needed to
reinstall. I can't think how my old and new Windows
installations differ, so if you get it working I'll be
interested to know how your Windows machine is set up
and also how you're building mono on Windows. I build
mono from source in cygwin using then build the
mono.dll using:

gcc -mno-cygwin -O -g -O2 -fno-strict-aliasing -g
-Wall -Wunused -Wmissing-prototypes
-Wmissing-declarations -Wstrict-prototypes
-Wmissing-prototypes -Wnested-externs -Wpointer-arith
-Wno-cast-qual -Wcast-align -Wwrite-strings -shared -o
mono.dll main.o -Wl,--export-dynamic
-Wl,--export-dynamic  ./.libs/libmono.a
-L/usr/local/lib -lgthread-2.0 -lgmodule-2.0
-lglib-2.0 -lintl -liconv -lws2_32 -lpsapi -lole32

I've looked in to building Mono in VS before, but at
the time I looked in to it there were problems with
stack walking, so not everything worked when you built
Mono with VS and also you needed VS 2005 which was
only in beta at the time and SL only built in VS 2003.

Cheers,

Jim.

--- Zoltan Varga <vargaz at gmail.com> wrote:

>                                                  
> Hi,
> 
>   I tried the example code which creates appdomains
> from C code and it
> really does crash
> because some things are only set up in the runtime
> when mono_jit_exec
> () is called. So
> your workaround of calling CreateDomain () from
> managed code seems to
> be the way to
> go, at least for now. I tried it and it seems to
> work on linux, I will
> try to look into the
> windows problems shortly.
> 
>                      Zoltan
> 
> On 1/11/06, Jim Purbrick <jimpurbrick at yahoo.co.uk>
> wrote:
> > Hi Robert/Lupus/Everyone,
> >
> > I've tried Robert's approach (which cleans my code
> up,
> > but is vulnerable to changes in _MonoAppDomain as
> > Paolo said), but I still get the same crash when
> > making the mono_runtime_invoke() call to
> > AppDomain.CreateDomain().
> >
> > At this point I'm struggling with the limited
> > debugging I can do in VS 2003 when the code calls
> in
> > to glib or the mono. The error I get is Unhandled
> > exception at 0x10059acc in debugsim.exe:
> 0xC0000005:
> > Access violation reading location 0x00000007. And
> the
> > call stack is:
> >
> >         mono.dll!10059acc()
> >         libglib-2.0-0.dll!0032bb3e()
> >         mono.dll!10059bad()
> >         libglib-2.0-0.dll!0032baf9()
> >         mono.dll!10059736()
> >         mono.dll!1002b3ba()
> >         mono.dll!1002b7a0()
> >         mono.dll!10067527()
> >         debugsim.exe!createDomain(const char *
> > name=0x0302edf8)  Line 31 + 0x11        C++
> >
> > Which doesn't tell me a lot. I wonder whether the
> > problem is something to do with my new Windows
> > configuration as the code worked fine with mono
> > 1.1.9.2 in my old Windows installation, but now I
> get
> > this problem with mono 1.1.9.2, 1.1.12.1 and
> 1.1.13.
> > Could some differences in the environment be
> causing
> > the problem? The value of MONO_PATH or some other
> > environment variable? This is just wild
> speculation
> > really. Is there anything else I can do to
> diagnose
> > the problem?
> >
> > At the moment I'm thinking the best thing to do
> might
> > be to #define the code to use a single AppDomain
> on
> > Windows and just do the secondary AppDomain
> creation
> > and unloading on Linux, which is our production
> > environment anyway. I'm loathe to make the 2
> versions
> > behave differently, but it would allow me to make
> some
> > forward progress while trying to sort this problem
> out
> > as a background task.
> >
> > Thanks for all your help on this.
> >
> > Cheers,
> >
> > Jim.
> >
> > --- Robert Jordan <robertj at gmx.net> wrote:
> >
> > > 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):
> > > >>
> > > >>MonoAppDomain*
> > > >>createDomain (char *name) ....
> > > >>
> > > >>void
> > > >>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.
> > >
> > > Robert
> >
> >
> >
> >
>
___________________________________________________________
> > Yahoo! Photos – NEW, now offering a quality print
> service from just 8p a photo
> http://uk.photos.yahoo.com
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com
> >
>
http://lists.ximian.com/mailman/listinfo/mono-devel-list
> >
> > _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
>
http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 



	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com



More information about the Mono-devel-list mailing list