Re: [Mono-dev] mono_method_desc_search_in_image problem, and some question...

2018-02-13 Thread R Zaghi
Just for the record, I mean write it in a C# class and load that one class
so you can handle everything in C# itself - much more robust.


On Tue, 13 Feb 2018 at 19:04, R Zaghi  wrote:

> If this is actually a problem with a library like mono then it sounds like
> a caching problem. If you build mono from source then it's easier to look
> into this...
>
> Compare your code with this example. In the example, the .dll assembly is
> re-loaded in a loop. You can see the clean up portion and the shutdown or
> initialisation portions too:
>
> https://github.com/ramin-zaghi/mono-embedding
>
> Regarding how to compile code at runtime without a system() call, you can
> use CodeDom (look it up) to compile from files, or in a mono-specific way
> use Mono Compiler Service (e.g the Evaluator and CompilerContext classes -
> google them) which allow you to evaluate partial expressions/statements/etc.
>
> I use both depending on situation and they work pretty well. Roslyn is
> apparently another option but let's not go there :)
>
> R.
>
>
>
>
>
> On Tue, 13 Feb 2018 at 16:17, pierre  wrote:
>
>> Thanks for the answer.
>>
>>
>> > you 100% sure the old files are all overwritten?
>> Yes, I have checked the file time... and also included a
>>
>> remove(fileName);
>>
>> to be sure!
>>
>>
>> >There are a couple of different ways to get compiled binary at runtime
>> without a system() call
>> Which ones?
>>
>> I have tried something:
>> calling mono_image_open_from_data_with_name and mono_assembly_load_from_full
>> with a different file name on every compile and it is working!!!
>>
>> so, the following code is not reloading properly:
>>
>> monoEngine->fileName = strdup("code.dll");
>>
>>
>> monoEngine->image = mono_image_open_from_data_with_name(data, dataLen,
>>   TRUE /* copy
>> data */,
>>   ,
>>   FALSE /* ref
>> only */,
>>
>> monoEngine->fileName);
>> if (status != MONO_IMAGE_OK || monoEngine->image == NULL)
>> {
>> }
>> monoEngine->assembly = mono_assembly_load_from_full(monoEngine->image,
>>
>> monoEngine->fileName,
>>   , FALSE);
>> if (status != MONO_IMAGE_OK || monoEngine->assembly == NULL)
>> {
>> }
>>
>>
>> but, the same with a different file name on every run (only the
>> monoEngine->fileName creation differ) is working:
>>
>> static int version = 1;
>> ...
>>
>> sprintf(monoEngine->fileName,  "code%03d.dll", version);
>> version ++;
>>
>>
>> monoEngine->image = mono_image_open_from_data_with_name(data, dataLen,
>>   TRUE /* copy
>> data */,
>>   ,
>>   FALSE /* ref
>> only */,
>>
>> monoEngine->fileName);
>> if (status != MONO_IMAGE_OK || monoEngine->image == NULL)
>> {
>> }
>> monoEngine->assembly = mono_assembly_load_from_full(monoEngine->image,
>>
>> monoEngine->fileName,
>>   , FALSE);
>> if (status != MONO_IMAGE_OK || monoEngine->assembly == NULL)
>> {
>> }
>>
>> Is there a wait to be introduced after a mono_domain_unload? It is like
>> doing mono_domain_unload, mono_image_open_from_data_with_name and 
>> mono_assembly_load_from_full
>> with the same file name is detected and the unload is not performed
>>
>>
>> > This is more likely to be a problem outside of mono.
>> I do agree... but I am running out of idea on why!!!
>>
>>
>> and for mono_method_desc_search_in_image? is it bug?
>>
>>
>> Pierre
>>
>>
>> On 13/02/2018 07:15, R Zaghi wrote:
>>
>> I think we need to know a bit more about what you are doing in the code
>> exactly but as a quick first guess if you are recompiling using a system()
>> call then are you 100% sure the old files are all overwritten? There are a
>> couple of different ways to get compiled binary at runtime without a
>> system() call which I prefer but if you are using a system() call then have
>> you tried two separate calls with two parallel binaries loaded as a start
>> to debug your code?
>>
>> This is more likely to be a problem outside of mono.
>>
>> Ramin
>>
>>
>>
>>
>> Ramin Zaghi
>>
>> *Mosaic3DX™ | User Interface Technology*
>> St John's Innovation Centre,
>> Cowley Road,
>> Cambridge,
>> CB4 0WS, UK
>> *E*: rza...@mosaic3dx.com
>> *T*: +44 1223 421 311 <+44%201223%20421311>
>> http://linkedin.com/in/raminzaghi
>>
>>
>>
>> On Tue, 13 Feb 2018 at 01:27, pierre 
>> wrote:
>>
>>> Hi,
>>>
>>> I am trying to embed mono... and I ran into a problem with the code:
>>>
>>> monoMethodDesc = mono_method_desc_new("Script:Main", 0);
>>> method = mono_method_desc_search_in_image(monoMethodDesc,
>>> monoEngine->image);
>>>
>>>
>>> It is returning a method on the cs code:

Re: [Mono-dev] mono_method_desc_search_in_image problem, and some question...

2018-02-13 Thread R Zaghi
If this is actually a problem with a library like mono then it sounds like
a caching problem. If you build mono from source then it's easier to look
into this...

Compare your code with this example. In the example, the .dll assembly is
re-loaded in a loop. You can see the clean up portion and the shutdown or
initialisation portions too:

https://github.com/ramin-zaghi/mono-embedding

Regarding how to compile code at runtime without a system() call, you can
use CodeDom (look it up) to compile from files, or in a mono-specific way
use Mono Compiler Service (e.g the Evaluator and CompilerContext classes -
google them) which allow you to evaluate partial expressions/statements/etc.

I use both depending on situation and they work pretty well. Roslyn is
apparently another option but let's not go there :)

R.





On Tue, 13 Feb 2018 at 16:17, pierre  wrote:

> Thanks for the answer.
>
>
> > you 100% sure the old files are all overwritten?
> Yes, I have checked the file time... and also included a
>
> remove(fileName);
>
> to be sure!
>
>
> >There are a couple of different ways to get compiled binary at runtime
> without a system() call
> Which ones?
>
> I have tried something:
> calling mono_image_open_from_data_with_name and mono_assembly_load_from_full
> with a different file name on every compile and it is working!!!
>
> so, the following code is not reloading properly:
>
> monoEngine->fileName = strdup("code.dll");
>
>
> monoEngine->image = mono_image_open_from_data_with_name(data, dataLen,
>   TRUE /* copy
> data */,
>   ,
>   FALSE /* ref
> only */,
>
> monoEngine->fileName);
> if (status != MONO_IMAGE_OK || monoEngine->image == NULL)
> {
> }
> monoEngine->assembly = mono_assembly_load_from_full(monoEngine->image,
>
> monoEngine->fileName,
>   , FALSE);
> if (status != MONO_IMAGE_OK || monoEngine->assembly == NULL)
> {
> }
>
>
> but, the same with a different file name on every run (only the
> monoEngine->fileName creation differ) is working:
>
> static int version = 1;
> ...
>
> sprintf(monoEngine->fileName,  "code%03d.dll", version);
> version ++;
>
>
> monoEngine->image = mono_image_open_from_data_with_name(data, dataLen,
>   TRUE /* copy
> data */,
>   ,
>   FALSE /* ref
> only */,
>
> monoEngine->fileName);
> if (status != MONO_IMAGE_OK || monoEngine->image == NULL)
> {
> }
> monoEngine->assembly = mono_assembly_load_from_full(monoEngine->image,
>
> monoEngine->fileName,
>   , FALSE);
> if (status != MONO_IMAGE_OK || monoEngine->assembly == NULL)
> {
> }
>
> Is there a wait to be introduced after a mono_domain_unload? It is like
> doing mono_domain_unload, mono_image_open_from_data_with_name and 
> mono_assembly_load_from_full
> with the same file name is detected and the unload is not performed
>
>
> > This is more likely to be a problem outside of mono.
> I do agree... but I am running out of idea on why!!!
>
>
> and for mono_method_desc_search_in_image? is it bug?
>
>
> Pierre
>
>
> On 13/02/2018 07:15, R Zaghi wrote:
>
> I think we need to know a bit more about what you are doing in the code
> exactly but as a quick first guess if you are recompiling using a system()
> call then are you 100% sure the old files are all overwritten? There are a
> couple of different ways to get compiled binary at runtime without a
> system() call which I prefer but if you are using a system() call then have
> you tried two separate calls with two parallel binaries loaded as a start
> to debug your code?
>
> This is more likely to be a problem outside of mono.
>
> Ramin
>
>
>
>
> Ramin Zaghi
>
> *Mosaic3DX™ | User Interface Technology*
> St John's Innovation Centre,
> Cowley Road,
> Cambridge,
> CB4 0WS, UK
> *E*: rza...@mosaic3dx.com
> *T*: +44 1223 421 311 <+44%201223%20421311>
> http://linkedin.com/in/raminzaghi
>
>
>
> On Tue, 13 Feb 2018 at 01:27, pierre  wrote:
>
>> Hi,
>>
>> I am trying to embed mono... and I ran into a problem with the code:
>>
>> monoMethodDesc = mono_method_desc_new("Script:Main", 0);
>> method = mono_method_desc_search_in_image(monoMethodDesc,
>> monoEngine->image);
>>
>>
>> It is returning a method on the cs code:
>>
>> public class Script
>> {
>>   static public void Main ()
>>   {
>> ScriptEngine.report("--Main Called ");
>>   }
>> }
>>
>>
>> but it is also returning a method on the cs code (with the wrong class
>> name):
>>
>> public class Script*2*
>> {
>>   static public void Main ()
>>   {
>> ScriptEngine.report("--Main Called ");
>>   }
>> }
>>
>> while it should only return