[Mono-dev] reloading mono domain or assemblies

2010-08-16 Thread marcus julius
Hi Lucas,

you can use mono_domain_create() and mono_domain_unload() just fine from 
c.  In fact, I suspect it's actually
easier to do from native code these days.  basically what you should do is:

create domain
set it active
load your assemblies
run your code

when you want to reload code,

unload the domain
load your assemblies again
run your code.

I actually found similar reply from you in another discussion 
and I am using this solution. 

However, I have a problem with one of the DLLs. I cannot delete it
because there are internal calls registered (mono_add_internal_call) 
from that DLL. I cannot delete that DLL even after unloading the domain.

I don't think it is related to loading an assembly from the disk instead
of memory because other DLL that does not have any method registered 
with mono can be deleted after unloading the domain.

Do you have any idea how to solve this?

Thanks.


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] reloading mono domain or assemblies

2010-08-13 Thread marcus julius
Hi,

We are developing a game and using C# and C++ with the help of mono. 

There are two dlls we use; Dll1 and Dll2. At run-time, I want to change 
(update) these dlls without restarting the game (which takes a while). Here is 
the code we use:

mono_domain = mono_jit_init(Dll1);

mono_world_assembly = mono_domain_assembly_open(mono_domain,Dll1);
mono_world_image = mono_assembly_get_image(mono_world_assembly);
       
mono_module_assembly = mono_domain_assembly_open(mono_domain, Dll2);
mono_module_image = mono_assembly_get_image(mono_module_assembly);

I tried two diferent ways, but neither was successful. I don't even know what 
is the exact error since I don't know how to debug mono in C++.

First approach was to use mono_jit_cleanup and then when the dlls are 
recompiled use the code above to reload the dlls.

Second approach was to close the assemblies and images and reopen them when the 
dlls are replaced.

Did I make a mistake and/or is there a way to do this? 

Thanks.


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] reloading mono domain or assemblies

2010-08-13 Thread Robert Jordan
On 13.08.2010 15:10, marcus julius wrote:

 Did I make a mistake and/or is there a way to do this?

Once an assembly has been JITed (which basically means that
one of its methods was invoked), there is no way to change it.

There are 2 ways to reload an assembly:

1) change its assembly name and load it again. Note that this
will not unload/release the types provided by the previous assembly,
nor are the types of the reloaded assembly compatible with those of
the first one. With other words: don't do it unless you've
understood these drawbacks.

2) Use app domains which can be unloaded together with
their assemblies by design.

This is a common pattern in the .NET word, and it can be
implemented easily in managed code. There are plenty of
docs/sample on the internets.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] reloading mono domain or assemblies

2010-08-13 Thread marcus julius
On 13.08.2010 15:10, marcus julius wrote:

 Did I make a mistake and/or is there a way to do this?

There are 2 ways to reload an assembly:

2) Use app domains which can be unloaded together with
their assemblies by design.
Thanks for the quick reply. 

Ok, I know how to do this in C#. Is there a way to create 
app domain using mono in C++? If there is, I can create 
my monoDomain and assemblies in that app domain, so I can unload them.

Otherwise, It won't help me to create an appdomain in C# since the 
Dlls I want to change are locked by the mono in C++.






___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] reloading mono domain or assemblies

2010-08-13 Thread Robert Jordan
On 13.08.2010 15:39, marcus julius wrote:
 On 13.08.2010 15:10, marcus julius wrote:

 Did I make a mistake and/or is there a way to do this?

 There are 2 ways to reload an assembly:

 2) Use app domains which can be unloaded together with
 their assemblies by design.
 Thanks for the quick reply.

 Ok, I know how to do this in C#. Is there a way to create
 app domain using mono in C++? If there is, I can create
 my monoDomain and assemblies in that app domain, so I can unload them.

 Otherwise, It won't help me to create an appdomain in C# since the
 Dlls I want to change are locked by the mono in C++.

Well, it doesn't really matter who's creating the domains
and loading the assemblies. It's by far easier to implement
this in C# and then mono_runtime_invoke it from C++.

Of course, you can invoke everything from C++ but this will
likely triplicate the amount of code to be written.

Furthermore, the only safe way to create a domain in C++ is
mono_runtime_invoke-ing System.AppDomain.CreateDomain(), IIRC.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] reloading mono domain or assemblies

2010-08-13 Thread Lucas Meijer
  On 8/13/10 4:04 PM, Robert Jordan wrote:
 Well, it doesn't really matter who's creating the domains
 and loading the assemblies. It's by far easier to implement
 this in C# and then mono_runtime_invoke it from C++.

 Of course, you can invoke everything from C++ but this will
 likely triplicate the amount of code to be written.

 Furthermore, the only safe way to create a domain in C++ is
 mono_runtime_invoke-ing System.AppDomain.CreateDomain(), IIRC.
you can use mono_domain_create() and mono_domain_unload() just fine from 
c.  In fact, I suspect it's actually
easier to do from native code these days.  basically what you should do is:

create domain
set it active
load your assemblies
run your code

when you want to reload code,

unload the domain
load your assemblies again
run your code.

It gets tricky though, as you need to somehow maintain the state of 
your program. We use custom serialization
to remember the state of all objects,   tear down everything,  load new 
assemblies,  recreate all objects, and reconfigure them the way they were.
not an easy task by any means.

also make sure you load your assemblies from memory instead of from 
disk.  at least on windows, if you read them from disk, you will not be 
allowed to
overwrite your assemblies with new ones.

domain unloading/reloading is a bit of a notorious area, with plenty of 
memory leaks and bugs.  mostly because it is a way to use mono that not that
many people seem to be doing.  I would say from all the mono related 
work I do at Unity, about 80% is related to problems relating to domain 
unloading.

Bye, Lucas
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] reloading mono domain or assemblies

2010-08-13 Thread Frank Fuchs
Well you could take a look at this code (http://monobin.com/__f7469 ), 
should be familiar to some of you ;)
For me it works perfectly under Win7 and MacOS X.

-Frank
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list