mono_method_desc_search_in_image problem, and some question...

pierre <[email protected]> Mon, 12 Feb 2018 18:26:49 +0100
Newsgroups gmane.comp.gnome.mono.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============3710915771723540634==
Content-Type: multipart/alternative;
 boundary="------------BA67977D1912D662FB89D8E9"
Content-Language: en-US

This is a multi-part message in MIME format.
--------------BA67977D1912D662FB89D8E9
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

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 for:

    monoMethodDesc = mono_method_desc_new("Script2:Main", 0);


Am i doing something wrong or is this a bug? It seem that 
mono_method_desc_search_in_image is returning a value if the actual 
class name is starting with the given  class name.... so, the same 
method is returned if I look for "Script:Main" but the declared class is 
"Script:Main", "Script_test:Main" or "Script2:Main"...

and a question:
is there a way to know if mono_domain_unload was successful or not?

I am creating an app domain per script so that I can recompile and 
reload the script at will...
I do not detect any error, but the new script seems not to replace the 
old one...
Basically, I am doing:

    res = mono_domain_set(rootDomain, FALSE);
    mono_domain_unload(monoEngine->domain);
    monoEngine->domain =
    mono_domain_create_appdomain("ScriptEngine-sub", NULL);

    data = readFile(f, &dataLen);
    fclose(f);
    monoEngine->image = mono_image_open_from_data_with_name(data, dataLen,
    TRUE /* copy data */,
    &status,
    FALSE /* ref only */,
    monoEngine->fileName);
       free(data);
       if (status != MONO_IMAGE_OK || monoEngine->image == NULL)
       {
         return FALSE;
       }

         // load the assembly
       monoEngine->assembly =
    mono_assembly_load_from_full(monoEngine->image,
    monoEngine->fileName,
    &status, FALSE);
       if (status != MONO_IMAGE_OK || monoEngine->assembly == NULL)
       {
         mono_image_close(monoEngine->image);
         return FALSE;
       }

but it does not seem to work. The code that runs is always the first 
loaded one!!

I also added the following code to my engine:

    mono_trace_set_log_handler(monoLogCallback, NULL);
    mono_trace_set_print_handler(monoPrintCallback);
    mono_trace_set_printerr_handler(monoPrintCallback);
    mono_trace_set_level_string ("debug");


but it is reporting debug info only on the first run... is there a way 
to having it working on every run?

Lastly, Is there a way to compile cs source without launching a

    system("msc.code.cs -target:library");

thanks in advance

Pierre



_______________________________________________
Mono-list maillist  [email protected]
http://lists.dot.net/mailman/listinfo/mono-list


--------------BA67977D1912D662FB89D8E9
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <pre wrap="">
</pre>
    <div class="moz-text-html" lang="x-western"> Hi,<br>
      <br>
      I am trying to embed mono... and I ran into a problem with the
      code: <br>
      <blockquote><tt>monoMethodDesc =
          mono_method_desc_new("Script:Main", 0);</tt><tt><br>
        </tt><tt>method =
          mono_method_desc_search_in_image(monoMethodDesc,
          monoEngine-&gt;image);</tt><br>
      </blockquote>
      <br>
      It is returning a method on the cs code:<br>
      <blockquote><tt>public class Script</tt><tt><br>
        </tt><tt>{</tt><tt><br>
        </tt><tt>  static public void Main ()</tt><tt><br>
        </tt><tt>  {</tt><tt><br>
        </tt><tt>    ScriptEngine.report("--Main Called ");</tt><tt><br>
        </tt><tt>  }</tt><tt><br>
        </tt><tt>}</tt><br>
      </blockquote>
      <br>
      but it is also returning a method on the cs code (with the wrong
      class name):<br>
      <br>
      <blockquote><tt>public class Script<b>2</b></tt><tt><br>
        </tt><tt> {</tt><tt><br>
        </tt><tt>   static public void Main ()</tt><tt><br>
        </tt><tt>   {</tt><tt><br>
        </tt><tt>     ScriptEngine.report("--Main Called ");</tt><tt><br>
        </tt><tt>   }</tt><tt><br>
        </tt><tt> }</tt><br>
      </blockquote>
      while it should only return for:<br>
      <blockquote><tt>monoMethodDesc =
          mono_method_desc_new("Script2:Main", 0);</tt><br>
      </blockquote>
      <tt>
      </tt><br>
      Am i doing something wrong or is this a bug? It seem that <tt>mono_method_desc_search_in_image
      </tt>is returning a value if the actual class name is starting
      with the given  class name.... so, the same method is returned if
      I look for "Script:Main" but the declared class is "Script:Main",
      "Script_test:Main" or "Script2:Main"...<br>
      <br>
      and a question:<br>
      is there a way to know if mono_domain_unload was successful or
      not? <br>
      <br>
      I am creating an app domain per script so that I can recompile and
      reload the script at will... <br>
      I do not detect any error, but the new script seems not to replace
      the old one...<br>
      Basically, I am doing:<br>
      <blockquote><tt>res = mono_domain_set(rootDomain, FALSE);</tt><br>
        <tt>mono_domain_unload(monoEngine-&gt;domain);</tt><br>
        <tt>monoEngine-&gt;domain =
          mono_domain_create_appdomain("ScriptEngine-sub", NULL);</tt><br>
        <br>
        <tt>data = readFile(f, &amp;dataLen);</tt><br>
        <tt>fclose(f);</tt><br>
        <tt>monoEngine-&gt;image =
          mono_image_open_from_data_with_name(data, dataLen, </tt><br>
        <tt>                                                         
          TRUE /* copy data */, </tt><br>
        <tt>                                                         
          &amp;status, </tt><br>
        <tt>                                                         
          FALSE /* ref only */, </tt><br>
        <tt>                                                         
          monoEngine-&gt;fileName);</tt><br>
        <tt>  free(data);</tt><br>
        <tt>  if (status != MONO_IMAGE_OK || monoEngine-&gt;image ==
          NULL)</tt><br>
        <tt>  {</tt><br>
        <tt>    return FALSE;</tt><br>
        <tt>  }</tt><br>
        <br>
        <tt>    // load the assembly</tt><br>
        <tt>  monoEngine-&gt;assembly =
          mono_assembly_load_from_full(monoEngine-&gt;image, </tt><br>
        <tt>                                                     
          monoEngine-&gt;fileName, </tt><br>
        <tt>                                                     
          &amp;status, FALSE);</tt><br>
        <tt>  if (status != MONO_IMAGE_OK || monoEngine-&gt;assembly ==
          NULL)</tt><br>
        <tt>  {</tt><br>
        <tt>    mono_image_close(monoEngine-&gt;image);</tt><br>
        <tt>    return FALSE;</tt><br>
        <tt>  }</tt><br>
      </blockquote>
      but it does not seem to work. The code that runs is always the
      first loaded one!! <br>
      <br>
      I also added the following code to my engine:<br>
      <blockquote><tt>mono_trace_set_log_handler(monoLogCallback, NULL);</tt><br>
        <tt>mono_trace_set_print_handler(monoPrintCallback);</tt><br>
        <tt>mono_trace_set_printerr_handler(monoPrintCallback);</tt><br>
        <tt>mono_trace_set_level_string ("debug");</tt><br>
      </blockquote>
      <br>
      but it is reporting debug info only on the first run... is there a
      way to having it working on every run?<br>
      <br>
      Lastly, Is there a way to compile cs source without launching a <br>
      <blockquote><tt>system("msc.code.cs -target:library");</tt><br>
      </blockquote>
      thanks in advance<br>
      <br>
      Pierre<br>
      <br>
    </div>
    <br>
    <fieldset class="mimeAttachmentHeader"></fieldset>
    <br>
    <div class="moz-text-plain" wrap="true" style="font-family:
      -moz-fixed; font-size: 14px;" lang="x-unicode">
      <pre wrap="">_______________________________________________
Mono-list maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://lists.dot.net/mailman/listinfo/mono-list">http://lists.dot.net/mailman/listinfo/mono-list</a>
</pre>
    </div>
  </body>
</html>

--------------BA67977D1912D662FB89D8E9--

--===============3710915771723540634==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KTW9uby1kZXZl
bC1saXN0IG1haWxpbmcgbGlzdApNb25vLWRldmVsLWxpc3RAbGlzdHMuZG90Lm5ldApodHRwOi8v
bGlzdHMuZG90Lm5ldC9tYWlsbWFuL2xpc3RpbmZvL21vbm8tZGV2ZWwtbGlzdAo=

--===============3710915771723540634==--