Embedding Mono Trouble

Jeremy <[email protected]> Wed, 19 Jul 2017 00:31:41 -0500
Newsgroups gmane.comp.gnome.mono.general
Message-ID <CAKKKtcF2m4UF1HxTS8aaQQeqdLdPLw5H+9dSeQDSK2C0xCQKOQ@mail.gmail.com>
--===============3107064936797671287==
Content-Type: multipart/alternative; boundary="001a11424c1a7259320554a4f241"

--001a11424c1a7259320554a4f241
Content-Type: text/plain; charset="UTF-8"

I've compiled and linked a small test C++ project with mono to experiment
with embedding and invoking functionality in a c# assembly. I will paste
the full code at the bottom, but what is happened is that when I try
to mono_jit_exec, passing a valid domain and assembly, and the assemblypath
as argv, I get a crash inside mono in mono_stack_mark_pop, where old_top is
null

+ handles 0x0124dc88 {top=0x01235810 {size=1 prev=0x00000000 <NULL>
next=0x00000000 <NULL> ...} bottom=0x01235810 {...} ...} HandleStack *
+ info 0x0122e9c0 {node={next=0x0128f5c8 {next=0x00000000 <NULL> key=26972
} key=26564 } small_id=64 native_handle=...} MonoThreadInfo *
+ old_top 0x00000000 <NULL> _HandleChunk *
- stackmark 0x00d7f138 {size=0 interior_size=0 chunk=0x00000000 <NULL>
} HandleStackMark
*
size 0 int
interior_size 0 int
+ chunk 0x00000000 <NULL> _HandleChunk *



I am trying to invoke an empty Main function in my test assembly, as I have
read that it is necessary to properly initialize things by calling Main
before you call other functions. Other functions crash in this same
location btw. This is in Windows 10 using MSVC 2015. I have a "MonoTestLib"
also in the 2015 project as a C# console application. Mono can seemingly
find the functions within the assembly
with mono_method_desc_search_in_image calls, but any attempt to invoke them
with mono_runtime_invoke crashes with the above.

Here is the code

//TestClass.cs
using System;

public class TestClass
{
    static public void StaticFunc()
    {
        Console.WriteLine("a TestClass!");
    }
    public void RunTest()
    {
        Console.WriteLine("TestClass!");
    }
    public void Test(int times)
    {
        for (var i = 0; i < times; ++i)
            Console.WriteLine("Test!");
    }

    static int Main(string[] args)
    {
        Console.WriteLine("Main!");
        return 0;
    }
}


// main.cpp with mono embed

#include <iostream>

#include <mono/jit/jit.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>


/* The C# signature for this method is: string GetMessage () in class
Sample */
MonoString* getMessage()
{
return mono_string_new( mono_domain_get(), "Hello, world" );
}

void NotifyAssemblyLoaded( MonoAssembly *assembly, void* user_data )
{
std::cout << "Assembly Loaded " << std::endl;
}

int main( int argc, char** argv )
{
/*
* Load the default Mono configuration file, this is needed
* if you are planning on using the dllmaps defined on the
* system configuration
*/
//mono_config_parse( NULL );
mono_set_dirs("C:\\Program Files (x86)\\Mono\\lib", "C:\\Program Files
(x86)\\Mono\\etc");

/*
* mono_jit_init() creates a domain: each assembly is
* loaded and run in a MonoDomain.
*/
//MonoDomain *domain = mono_jit_init( "MonoTestLib.dll" );
MonoDomain *domain = mono_jit_init_version( "TestApp", "v4.0.30319" );

mono_install_assembly_load_hook( NotifyAssemblyLoaded, NULL );

/*
* Optionally, add an internal call that your startup.exe
* code can call, this will bridge startup.exe to Mono
*/
//mono_add_internal_call( "Sample::GetMessage", getMessage );

//Open a assembly in the domain
char* assemblyPath =
"D:\\git\\voxel_component_system\\VoxelComponentSystem\\MonoTestLib\\bin\\Debug\\MonoTestLib.exe";
MonoAssembly *assembly = mono_domain_assembly_open( domain, assemblyPath );
if ( !assembly )
{
std::cout << "mono_domain_assembly_open failed" << std::endl;
system( "pause" );
return 1;
}

MonoImage* image = mono_assembly_get_image( assembly );
if ( !image )
{
std::cout << "mono_assembly_get_image failed" << std::endl;
system( "pause" );
return 1;
}

// mono_jit_exec expects the assembly path
argv[ 0 ] = assemblyPath;
int resmain = mono_jit_exec( domain, assembly, argc, argv );
if(resmain != 0)
{
std::cout << "mono_jit_exec failed" << std::endl;
system( "pause" );
return 1;
}

#pragma region Run a static method
{
//Build a method description object
const char* TypeMethodDescStr = "TestClass:StaticFunc()";
MonoMethodDesc* TypeMethodDesc = mono_method_desc_new( TypeMethodDescStr,
NULL );
if ( !TypeMethodDesc )
{
std::cout << "mono_method_desc_new failed" << std::endl;
system( "pause" );
return 1;
}

//Search the method in the image
MonoMethod* method = mono_method_desc_search_in_image( TypeMethodDesc,
image );
if ( !method )
{
std::cout << "mono_method_desc_search_in_image failed" << std::endl;
system( "pause" );
return 1;
}

//run the method
std::cout << "Running the static method: " << TypeMethodDescStr <<
std::endl;
mono_runtime_invoke( method, nullptr, nullptr, nullptr ); // CRASH
}
#pragma endregion

#pragma region Run a normal method
{
//Get the class
MonoClass* testClass = mono_class_from_name_case( image, "", "TestClass" );
if ( !testClass )
{
std::cout << "mono_class_from_name failed" << std::endl;
system( "pause" );
return 1;
}

//Create a instance of the class
MonoObject* testObj = mono_object_new( domain, testClass );
if ( !testObj )
{
std::cout << "mono_object_new failed" << std::endl;
system( "pause" );
return 1;
}

//Call its default constructor
mono_runtime_object_init( testObj );

//Build a method description object
const char* BarkMethodDescStr = "TestClass:Test(int)";
MonoMethodDesc* BarkMethodDesc = mono_method_desc_new( BarkMethodDescStr,
NULL );
if ( !BarkMethodDesc )
{
std::cout << "mono_method_desc_new failed" << std::endl;
system( "pause" );
return 1;
}

//Search the method in the image
MonoMethod* method = mono_method_desc_search_in_image( BarkMethodDesc,
image );
if ( !method )
{
std::cout << "mono_method_desc_search_in_image failed" << std::endl;
system( "pause" );
return 1;
}

//Set the arguments for the method
void* args[ 1 ];
int barkTimes = 3;
args[ 0 ] = &barkTimes;

//Run the method
std::cout << "Running the method: " << BarkMethodDescStr << std::endl;
mono_runtime_invoke( method, testObj, args, nullptr ); // CRASH
}
#pragma endregion


return 0;
}





// callstack

  mono-2.0-sgen.dll!mono_stack_mark_pop(MonoThreadInfo * info=0x00173600,
HandleStackMark * stackmark=0x0141ee78) Line 148 C
  mono-2.0-sgen.dll!mono_icall_end(MonoThreadInfo * info=0x00173600,
HandleStackMark * stackmark=0x0141ee78, _MonoError * error=0x0141ee80) Line
12398 C
  00f85394() Unknown
  [Frames below may be incorrect and/or missing]
  00f852d4() Unknown
  00f85294() Unknown
  00f84e90() Unknown
  00ec1c04() Unknown
  00ec13d8() Unknown
  00ec0fc5() Unknown
  mono-2.0-sgen.dll!mono_jit_runtime_invoke(_MonoMethod *
method=0x00230890, void * obj=0x00000000, void * * params=0x00000000,
_MonoObject * * exc=0x0141f1b8, _MonoError * error=0x0141f45c) Line 2794 C
  mono-2.0-sgen.dll!do_runtime_invoke(_MonoMethod * method=0x00230890, void
* obj=0x00000000, void * * params=0x00000000, _MonoObject * *
exc=0x0141f1b8, _MonoError * error=0x0141f45c) Line 2827 C
  mono-2.0-sgen.dll!mono_runtime_try_invoke(_MonoMethod *
method=0x00230890, void * obj=0x00000000, void * * params=0x00000000,
_MonoObject * * exc=0x0141f1b8, _MonoError * error=0x0141f45c) Line 2934 C
  mono-2.0-sgen.dll!mono_runtime_class_init_full(MonoVTable *
vtable=0x0022b5c0, _MonoError * error=0x0141f45c) Line 471 C
  mono-2.0-sgen.dll!mono_jit_compile_method_inner(_MonoMethod *
method=0x00230b08, _MonoDomain * target_domain=0x00170900, int
opt=378628607, _MonoError * error=0x0141f45c) Line 4331 C
  mono-2.0-sgen.dll!mono_jit_compile_method_with_opt(_MonoMethod *
method=0x00230b08, unsigned int opt=378628607, int jit_only=0, _MonoError *
error=0x0141f45c) Line 2132 C
  mono-2.0-sgen.dll!mono_jit_compile_method(_MonoMethod *
method=0x00230b08, _MonoError * error=0x0141f45c) Line 2178 C
  mono-2.0-sgen.dll!common_call_trampoline(int * regs=0x0141f4d0, unsigned
char * code=0x00ec11e4, _MonoMethod * m=0x00230b08, MonoVTable *
vt=0x00000000, void * * vtable_slot=0x00000000, _MonoError *
error=0x0141f45c) Line 704 C
  mono-2.0-sgen.dll!mono_magic_trampoline(int * regs=0x0141f4d0, unsigned
char * code=0x00ec11e4, void * arg=0x00230b08, unsigned char *
tramp=0x00000000) Line 834 C
  00eb0188() Unknown
  00230b08() Unknown
  00ec12bc() Unknown
  mono-2.0-sgen.dll!mono_jit_runtime_invoke(_MonoMethod *
method=0x00219710, void * obj=0x00000000, void * * params=0x0141f640,
_MonoObject * * exc=0x00000000, _MonoError * error=0x0141f6b8) Line 2794 C
  mono-2.0-sgen.dll!do_runtime_invoke(_MonoMethod * method=0x00219710, void
* obj=0x00000000, void * * params=0x0141f640, _MonoObject * *
exc=0x00000000, _MonoError * error=0x0141f6b8) Line 2827 C
  mono-2.0-sgen.dll!mono_runtime_invoke_checked(_MonoMethod *
method=0x00219710, void * obj=0x00000000, void * * params=0x0141f640,
_MonoError * error=0x0141f6b8) Line 2980 C
> mono-2.0-sgen.dll!do_exec_main_checked(_MonoMethod * method=0x00219710,
_MonoArray * args=0x02c00290, _MonoError * error=0x0141f6b8) Line 4697 C
  mono-2.0-sgen.dll!mono_runtime_exec_main_checked(_MonoMethod *
method=0x00219710, _MonoArray * args=0x02c00290, _MonoError *
error=0x0141f6b8) Line 4798 C
  mono-2.0-sgen.dll!mono_runtime_run_main_checked(_MonoMethod *
method=0x00219710, int argc=1, char * * argv=0x00171538, _MonoError *
error=0x0141f6b8) Line 4226 C
  mono-2.0-sgen.dll!mono_jit_exec(_MonoDomain * domain=0x00170900,
_MonoAssembly * assembly=0x0016db00, int argc=1, char * * argv=0x00171538)
Line 1027 C
  MonoTest.exe!main(int argc=1, char * * argv=0x00171538) Line 65 C++
  MonoTest.exe!invoke_main() Line 64 C++
  MonoTest.exe!__scrt_common_main_seh() Line 253 C++
  MonoTest.exe!__scrt_common_main() Line 296 C++
  MonoTest.exe!mainCRTStartup() Line 17 C++
  kernel32.dll!@BaseThreadInitThunk@12 () Unknown
  ntdll.dll!__RtlUserThreadStart() Unknown
  ntdll.dll!__RtlUserThreadStart@8 () Unknown

--001a11424c1a7259320554a4f241
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I&#39;ve compiled and linked a small test C++ project with=
 mono to experiment with embedding and invoking functionality in a c# assem=
bly. I will paste the full code at the bottom, but what is happened is that=
 when I try to=C2=A0mono_jit_exec, passing a valid domain and assembly, and=
 the assemblypath as argv, I get a crash inside mono in=C2=A0mono_stack_mar=
k_pop, where old_top is null<br><br><div><div>+<span style=3D"white-space:p=
re">		</span>handles<span style=3D"white-space:pre">	</span>0x0124dc88 {top=
=3D0x01235810 {size=3D1 prev=3D0x00000000 &lt;NULL&gt; next=3D0x00000000 &l=
t;NULL&gt; ...} bottom=3D0x01235810 {...} ...}<span style=3D"white-space:pr=
e">	</span>HandleStack *</div><div>+<span style=3D"white-space:pre">		</spa=
n>info<span style=3D"white-space:pre">	</span>0x0122e9c0 {node=3D{next=3D0x=
0128f5c8 {next=3D0x00000000 &lt;NULL&gt; key=3D26972 } key=3D26564 } small_=
id=3D64 native_handle=3D...}<span style=3D"white-space:pre">	</span>MonoThr=
eadInfo *</div><div>+<span style=3D"white-space:pre">		</span>old_top<span =
style=3D"white-space:pre">	</span>0x00000000 &lt;NULL&gt;<span style=3D"whi=
te-space:pre">	</span>_HandleChunk *</div><div>-<span style=3D"white-space:=
pre">		</span>stackmark<span style=3D"white-space:pre">	</span>0x00d7f138 {=
size=3D0 interior_size=3D0 chunk=3D0x00000000 &lt;NULL&gt; }<span style=3D"=
white-space:pre">	</span>HandleStackMark *</div><div><span style=3D"white-s=
pace:pre">		</span>size<span style=3D"white-space:pre">	</span>0<span style=
=3D"white-space:pre">	</span>int</div><div><span style=3D"white-space:pre">=
		</span>interior_size<span style=3D"white-space:pre">	</span>0<span style=
=3D"white-space:pre">	</span>int</div><div>+<span style=3D"white-space:pre"=
>		</span>chunk<span style=3D"white-space:pre">	</span>0x00000000 &lt;NULL&=
gt;<span style=3D"white-space:pre">	</span>_HandleChunk *</div></div><div><=
br></div><div><br></div><div><br></div><div>I am trying to invoke an empty =
Main function in my test assembly, as I have read that it is necessary to p=
roperly initialize things by calling Main before you call other functions. =
Other functions crash in this same location btw. This is in Windows 10 usin=
g MSVC 2015. I have a &quot;MonoTestLib&quot; also in the 2015 project as a=
 C# console application. Mono can seemingly find the functions within the a=
ssembly with=C2=A0mono_method_desc_search_in_image calls, but any attempt t=
o invoke them with=C2=A0mono_runtime_invoke crashes with the above.</div><d=
iv><br></div><div>Here is the code=C2=A0</div><div><br></div><div>//TestCla=
ss.cs</div><div><div>using System;</div><div><br></div><div>public class Te=
stClass</div><div>{</div><div>=C2=A0 =C2=A0 static public void StaticFunc()=
</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Console.Wr=
iteLine(&quot;a TestClass!&quot;);</div><div>=C2=A0 =C2=A0 }</div><div>=C2=
=A0 =C2=A0 public void RunTest()</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 Console.WriteLine(&quot;TestClass!&quot;);</div><div>=
=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 public void Test(int times)</div><d=
iv>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 for (var i =3D 0; =
i &lt; times; ++i)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Cons=
ole.WriteLine(&quot;Test!&quot;);</div><div>=C2=A0 =C2=A0 }</div><div><br><=
/div><div>=C2=A0 =C2=A0 static int Main(string[] args)</div><div>=C2=A0 =C2=
=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Console.WriteLine(&quot;Main!&q=
uot;);</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return 0;</div><div>=C2=A0 =C2=
=A0 }</div><div>}</div></div><div><br></div><div><br></div><div>// main.cpp=
 with mono embed</div><div><br></div><div><div>#include &lt;iostream&gt;</d=
iv><div><br></div><div>#include &lt;mono/jit/jit.h&gt;</div><div>#include &=
lt;mono/metadata/mono-config.h&gt;</div><div>#include &lt;mono/metadata/ass=
embly.h&gt;</div><div>#include &lt;mono/metadata/debug-helpers.h&gt;</div><=
div><br></div><div><br></div><div>/* The C# signature for this method is: s=
tring GetMessage () in class Sample */</div><div>MonoString* getMessage()</=
div><div>{</div><div><span style=3D"white-space:pre">	</span>return mono_st=
ring_new( mono_domain_get(), &quot;Hello, world&quot; );</div><div>}</div><=
div><br></div><div>void NotifyAssemblyLoaded( MonoAssembly *assembly, void*=
 user_data )</div><div>{</div><div><span style=3D"white-space:pre">	</span>=
std::cout &lt;&lt; &quot;Assembly Loaded &quot; &lt;&lt; std::endl;</div><d=
iv>}</div><div><br></div><div>int main( int argc, char** argv )</div><div>{=
</div><div><span style=3D"white-space:pre">	</span>/*</div><div><span style=
=3D"white-space:pre">	</span>* Load the default Mono configuration file, th=
is is needed</div><div><span style=3D"white-space:pre">	</span>* if you are=
 planning on using the dllmaps defined on the</div><div><span style=3D"whit=
e-space:pre">	</span>* system configuration</div><div><span style=3D"white-=
space:pre">	</span>*/</div><div><span style=3D"white-space:pre">	</span>//m=
ono_config_parse( NULL );</div><div><span style=3D"white-space:pre">	</span=
>mono_set_dirs(&quot;C:\\Program Files (x86)\\Mono\\lib&quot;, &quot;C:\\Pr=
ogram Files (x86)\\Mono\\etc&quot;);</div><div><br></div><div><span style=
=3D"white-space:pre">	</span>/*</div><div><span style=3D"white-space:pre">	=
</span>* mono_jit_init() creates a domain: each assembly is</div><div><span=
 style=3D"white-space:pre">	</span>* loaded and run in a MonoDomain.</div><=
div><span style=3D"white-space:pre">	</span>*/</div><div><span style=3D"whi=
te-space:pre">	</span>//MonoDomain *domain =3D mono_jit_init( &quot;MonoTes=
tLib.dll&quot; );</div><div><span style=3D"white-space:pre">	</span>MonoDom=
ain *domain =3D mono_jit_init_version( &quot;TestApp&quot;, &quot;v4.0.3031=
9&quot; );</div><div><br></div><div><span style=3D"white-space:pre">	</span=
>mono_install_assembly_load_hook( NotifyAssemblyLoaded, NULL );</div><div><=
br></div><div><span style=3D"white-space:pre">	</span>/*</div><div><span st=
yle=3D"white-space:pre">	</span>* Optionally, add an internal call that you=
r startup.exe</div><div><span style=3D"white-space:pre">	</span>* code can =
call, this will bridge startup.exe to Mono</div><div><span style=3D"white-s=
pace:pre">	</span>*/</div><div><span style=3D"white-space:pre">	</span>//mo=
no_add_internal_call( &quot;Sample::GetMessage&quot;, getMessage );</div><d=
iv><br></div><div><span style=3D"white-space:pre">	</span>//Open a assembly=
 in the domain<span style=3D"white-space:pre">	</span></div><div><span styl=
e=3D"white-space:pre">	</span>char* assemblyPath =3D &quot;D:\\git\\voxel_c=
omponent_system\\VoxelComponentSystem\\MonoTestLib\\bin\\Debug\\MonoTestLib=
.exe&quot;;</div><div><span style=3D"white-space:pre">	</span>MonoAssembly =
*assembly =3D mono_domain_assembly_open( domain, assemblyPath );</div><div>=
<span style=3D"white-space:pre">	</span>if ( !assembly )</div><div><span st=
yle=3D"white-space:pre">	</span>{</div><div><span style=3D"white-space:pre"=
>		</span>std::cout &lt;&lt; &quot;mono_domain_assembly_open failed&quot; &=
lt;&lt; std::endl;</div><div><span style=3D"white-space:pre">		</span>syste=
m( &quot;pause&quot; );</div><div><span style=3D"white-space:pre">		</span>=
return 1;</div><div><span style=3D"white-space:pre">	</span>}</div><div><br=
></div><div><span style=3D"white-space:pre">	</span>MonoImage* image =3D mo=
no_assembly_get_image( assembly );</div><div><span style=3D"white-space:pre=
">	</span>if ( !image )</div><div><span style=3D"white-space:pre">	</span>{=
</div><div><span style=3D"white-space:pre">		</span>std::cout &lt;&lt; &quo=
t;mono_assembly_get_image failed&quot; &lt;&lt; std::endl;</div><div><span =
style=3D"white-space:pre">		</span>system( &quot;pause&quot; );</div><div><=
span style=3D"white-space:pre">		</span>return 1;</div><div><span style=3D"=
white-space:pre">	</span>}</div><div><br></div><div><span style=3D"white-sp=
ace:pre">	</span>// mono_jit_exec expects the assembly path</div><div><span=
 style=3D"white-space:pre">	</span>argv[ 0 ] =3D assemblyPath;</div><div><s=
pan style=3D"white-space:pre">	</span>int resmain =3D mono_jit_exec( domain=
, assembly, argc, argv );</div><div><span style=3D"white-space:pre">	</span=
>if(resmain !=3D 0)</div><div><span style=3D"white-space:pre">	</span>{</di=
v><div><span style=3D"white-space:pre">		</span>std::cout &lt;&lt; &quot;mo=
no_jit_exec failed&quot; &lt;&lt; std::endl;</div><div><span style=3D"white=
-space:pre">		</span>system( &quot;pause&quot; );</div><div><span style=3D"=
white-space:pre">		</span>return 1;</div><div><span style=3D"white-space:pr=
e">	</span>}</div><div><br></div><div>#pragma region Run a static method</d=
iv><div><span style=3D"white-space:pre">	</span>{</div><div><span style=3D"=
white-space:pre">		</span>//Build a method description object</div><div><sp=
an style=3D"white-space:pre">		</span>const char* TypeMethodDescStr =3D &qu=
ot;TestClass:StaticFunc()&quot;;</div><div><span style=3D"white-space:pre">=
		</span>MonoMethodDesc* TypeMethodDesc =3D mono_method_desc_new( TypeMetho=
dDescStr, NULL );</div><div><span style=3D"white-space:pre">		</span>if ( !=
TypeMethodDesc )</div><div><span style=3D"white-space:pre">		</span>{</div>=
<div><span style=3D"white-space:pre">			</span>std::cout &lt;&lt; &quot;mon=
o_method_desc_new failed&quot; &lt;&lt; std::endl;</div><div><span style=3D=
"white-space:pre">			</span>system( &quot;pause&quot; );</div><div><span st=
yle=3D"white-space:pre">			</span>return 1;</div><div><span style=3D"white-=
space:pre">		</span>}</div><div><br></div><div><span style=3D"white-space:p=
re">		</span>//Search the method in the image</div><div><span style=3D"whit=
e-space:pre">		</span>MonoMethod* method =3D mono_method_desc_search_in_ima=
ge( TypeMethodDesc, image );</div><div><span style=3D"white-space:pre">		</=
span>if ( !method )</div><div><span style=3D"white-space:pre">		</span>{</d=
iv><div><span style=3D"white-space:pre">			</span>std::cout &lt;&lt; &quot;=
mono_method_desc_search_in_image failed&quot; &lt;&lt; std::endl;</div><div=
><span style=3D"white-space:pre">			</span>system( &quot;pause&quot; );</di=
v><div><span style=3D"white-space:pre">			</span>return 1;</div><div><span =
style=3D"white-space:pre">		</span>}</div><div><br></div><div><span style=
=3D"white-space:pre">		</span>//run the method</div><div><span style=3D"whi=
te-space:pre">		</span>std::cout &lt;&lt; &quot;Running the static method: =
&quot; &lt;&lt; TypeMethodDescStr &lt;&lt; std::endl;</div><div><span style=
=3D"white-space:pre">		</span>mono_runtime_invoke( method, nullptr, nullptr=
, nullptr ); // CRASH</div><div><span style=3D"white-space:pre">	</span>}</=
div><div>#pragma endregion</div><div><br></div><div>#pragma region Run a no=
rmal method</div><div><span style=3D"white-space:pre">	</span>{</div><div><=
span style=3D"white-space:pre">		</span>//Get the class</div><div><span sty=
le=3D"white-space:pre">		</span>MonoClass* testClass =3D mono_class_from_na=
me_case( image, &quot;&quot;, &quot;TestClass&quot; );</div><div><span styl=
e=3D"white-space:pre">		</span>if ( !testClass )</div><div><span style=3D"w=
hite-space:pre">		</span>{</div><div><span style=3D"white-space:pre">			</s=
pan>std::cout &lt;&lt; &quot;mono_class_from_name failed&quot; &lt;&lt; std=
::endl;</div><div><span style=3D"white-space:pre">			</span>system( &quot;p=
ause&quot; );</div><div><span style=3D"white-space:pre">			</span>return 1;=
</div><div><span style=3D"white-space:pre">		</span>}</div><div><br></div><=
div><span style=3D"white-space:pre">		</span>//Create a instance of the cla=
ss</div><div><span style=3D"white-space:pre">		</span>MonoObject* testObj =
=3D mono_object_new( domain, testClass );</div><div><span style=3D"white-sp=
ace:pre">		</span>if ( !testObj )</div><div><span style=3D"white-space:pre"=
>		</span>{</div><div><span style=3D"white-space:pre">			</span>std::cout &=
lt;&lt; &quot;mono_object_new failed&quot; &lt;&lt; std::endl;</div><div><s=
pan style=3D"white-space:pre">			</span>system( &quot;pause&quot; );</div><=
div><span style=3D"white-space:pre">			</span>return 1;</div><div><span sty=
le=3D"white-space:pre">		</span>}</div><div><br></div><div><span style=3D"w=
hite-space:pre">		</span>//Call its default constructor</div><div><span sty=
le=3D"white-space:pre">		</span>mono_runtime_object_init( testObj );</div><=
div><br></div><div><span style=3D"white-space:pre">		</span>//Build a metho=
d description object</div><div><span style=3D"white-space:pre">		</span>con=
st char* BarkMethodDescStr =3D &quot;TestClass:Test(int)&quot;;</div><div><=
span style=3D"white-space:pre">		</span>MonoMethodDesc* BarkMethodDesc =3D =
mono_method_desc_new( BarkMethodDescStr, NULL );</div><div><span style=3D"w=
hite-space:pre">		</span>if ( !BarkMethodDesc )</div><div><span style=3D"wh=
ite-space:pre">		</span>{</div><div><span style=3D"white-space:pre">			</sp=
an>std::cout &lt;&lt; &quot;mono_method_desc_new failed&quot; &lt;&lt; std:=
:endl;</div><div><span style=3D"white-space:pre">			</span>system( &quot;pa=
use&quot; );</div><div><span style=3D"white-space:pre">			</span>return 1;<=
/div><div><span style=3D"white-space:pre">		</span>}</div><div><br></div><d=
iv><span style=3D"white-space:pre">		</span>//Search the method in the imag=
e</div><div><span style=3D"white-space:pre">		</span>MonoMethod* method =3D=
 mono_method_desc_search_in_image( BarkMethodDesc, image );</div><div><span=
 style=3D"white-space:pre">		</span>if ( !method )</div><div><span style=3D=
"white-space:pre">		</span>{</div><div><span style=3D"white-space:pre">			<=
/span>std::cout &lt;&lt; &quot;mono_method_desc_search_in_image failed&quot=
; &lt;&lt; std::endl;</div><div><span style=3D"white-space:pre">			</span>s=
ystem( &quot;pause&quot; );</div><div><span style=3D"white-space:pre">			</=
span>return 1;</div><div><span style=3D"white-space:pre">		</span>}</div><d=
iv><br></div><div><span style=3D"white-space:pre">		</span>//Set the argume=
nts for the method</div><div><span style=3D"white-space:pre">		</span>void*=
 args[ 1 ];</div><div><span style=3D"white-space:pre">		</span>int barkTime=
s =3D 3;</div><div><span style=3D"white-space:pre">		</span>args[ 0 ] =3D &=
amp;barkTimes;</div><div><br></div><div><span style=3D"white-space:pre">		<=
/span>//Run the method</div><div><span style=3D"white-space:pre">		</span>s=
td::cout &lt;&lt; &quot;Running the method: &quot; &lt;&lt; BarkMethodDescS=
tr &lt;&lt; std::endl;</div><div><span style=3D"white-space:pre">		</span>m=
ono_runtime_invoke( method, testObj, args, nullptr ); // CRASH</div><div><s=
pan style=3D"white-space:pre">	</span>}</div><div>#pragma endregion</div><d=
iv><br></div><div><br></div><div><span style=3D"white-space:pre">		</span><=
/div><div><span style=3D"white-space:pre">	</span>return 0;</div><div>}</di=
v></div><div><br></div><div><br></div><div><br></div><div><br></div><div><b=
r></div><div>// callstack</div><div><br></div><div><div>=C2=A0<span style=
=3D"white-space:pre">	</span>mono-2.0-sgen.dll!mono_stack_mark_pop(MonoThre=
adInfo * info=3D0x00173600, HandleStackMark * stackmark=3D0x0141ee78) Line =
148<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span style=3D=
"white-space:pre">	</span>mono-2.0-sgen.dll!mono_icall_end(MonoThreadInfo *=
 info=3D0x00173600, HandleStackMark * stackmark=3D0x0141ee78, _MonoError * =
error=3D0x0141ee80) Line 12398<span style=3D"white-space:pre">	</span>C</di=
v><div>=C2=A0<span style=3D"white-space:pre">	</span>00f85394()<span style=
=3D"white-space:pre">	</span>Unknown</div><div>=C2=A0<span style=3D"white-s=
pace:pre">	</span>[Frames below may be incorrect and/or missing]<span style=
=3D"white-space:pre">	</span></div><div>=C2=A0<span style=3D"white-space:pr=
e">	</span>00f852d4()<span style=3D"white-space:pre">	</span>Unknown</div><=
div>=C2=A0<span style=3D"white-space:pre">	</span>00f85294()<span style=3D"=
white-space:pre">	</span>Unknown</div><div>=C2=A0<span style=3D"white-space=
:pre">	</span>00f84e90()<span style=3D"white-space:pre">	</span>Unknown</di=
v><div>=C2=A0<span style=3D"white-space:pre">	</span>00ec1c04()<span style=
=3D"white-space:pre">	</span>Unknown</div><div>=C2=A0<span style=3D"white-s=
pace:pre">	</span>00ec13d8()<span style=3D"white-space:pre">	</span>Unknown=
</div><div>=C2=A0<span style=3D"white-space:pre">	</span>00ec0fc5()<span st=
yle=3D"white-space:pre">	</span>Unknown</div><div>=C2=A0<span style=3D"whit=
e-space:pre">	</span>mono-2.0-sgen.dll!mono_jit_runtime_invoke(_MonoMethod =
* method=3D0x00230890, void * obj=3D0x00000000, void * * params=3D0x0000000=
0, _MonoObject * * exc=3D0x0141f1b8, _MonoError * error=3D0x0141f45c) Line =
2794<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span style=
=3D"white-space:pre">	</span>mono-2.0-sgen.dll!do_runtime_invoke(_MonoMetho=
d * method=3D0x00230890, void * obj=3D0x00000000, void * * params=3D0x00000=
000, _MonoObject * * exc=3D0x0141f1b8, _MonoError * error=3D0x0141f45c) Lin=
e 2827<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span style=
=3D"white-space:pre">	</span>mono-2.0-sgen.dll!mono_runtime_try_invoke(_Mon=
oMethod * method=3D0x00230890, void * obj=3D0x00000000, void * * params=3D0=
x00000000, _MonoObject * * exc=3D0x0141f1b8, _MonoError * error=3D0x0141f45=
c) Line 2934<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span=
 style=3D"white-space:pre">	</span>mono-2.0-sgen.dll!mono_runtime_class_ini=
t_full(MonoVTable * vtable=3D0x0022b5c0, _MonoError * error=3D0x0141f45c) L=
ine 471<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span styl=
e=3D"white-space:pre">	</span>mono-2.0-sgen.dll!mono_jit_compile_method_inn=
er(_MonoMethod * method=3D0x00230b08, _MonoDomain * target_domain=3D0x00170=
900, int opt=3D378628607, _MonoError * error=3D0x0141f45c) Line 4331<span s=
tyle=3D"white-space:pre">	</span>C</div><div>=C2=A0<span style=3D"white-spa=
ce:pre">	</span>mono-2.0-sgen.dll!mono_jit_compile_method_with_opt(_MonoMet=
hod * method=3D0x00230b08, unsigned int opt=3D378628607, int jit_only=3D0, =
_MonoError * error=3D0x0141f45c) Line 2132<span style=3D"white-space:pre">	=
</span>C</div><div>=C2=A0<span style=3D"white-space:pre">	</span>mono-2.0-s=
gen.dll!mono_jit_compile_method(_MonoMethod * method=3D0x00230b08, _MonoErr=
or * error=3D0x0141f45c) Line 2178<span style=3D"white-space:pre">	</span>C=
</div><div>=C2=A0<span style=3D"white-space:pre">	</span>mono-2.0-sgen.dll!=
common_call_trampoline(int * regs=3D0x0141f4d0, unsigned char * code=3D0x00=
ec11e4, _MonoMethod * m=3D0x00230b08, MonoVTable * vt=3D0x00000000, void * =
* vtable_slot=3D0x00000000, _MonoError * error=3D0x0141f45c) Line 704<span =
style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span style=3D"white-sp=
ace:pre">	</span>mono-2.0-sgen.dll!mono_magic_trampoline(int * regs=3D0x014=
1f4d0, unsigned char * code=3D0x00ec11e4, void * arg=3D0x00230b08, unsigned=
 char * tramp=3D0x00000000) Line 834<span style=3D"white-space:pre">	</span=
>C</div><div>=C2=A0<span style=3D"white-space:pre">	</span>00eb0188()<span =
style=3D"white-space:pre">	</span>Unknown</div><div>=C2=A0<span style=3D"wh=
ite-space:pre">	</span>00230b08()<span style=3D"white-space:pre">	</span>Un=
known</div><div>=C2=A0<span style=3D"white-space:pre">	</span>00ec12bc()<sp=
an style=3D"white-space:pre">	</span>Unknown</div><div>=C2=A0<span style=3D=
"white-space:pre">	</span>mono-2.0-sgen.dll!mono_jit_runtime_invoke(_MonoMe=
thod * method=3D0x00219710, void * obj=3D0x00000000, void * * params=3D0x01=
41f640, _MonoObject * * exc=3D0x00000000, _MonoError * error=3D0x0141f6b8) =
Line 2794<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span st=
yle=3D"white-space:pre">	</span>mono-2.0-sgen.dll!do_runtime_invoke(_MonoMe=
thod * method=3D0x00219710, void * obj=3D0x00000000, void * * params=3D0x01=
41f640, _MonoObject * * exc=3D0x00000000, _MonoError * error=3D0x0141f6b8) =
Line 2827<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span st=
yle=3D"white-space:pre">	</span>mono-2.0-sgen.dll!mono_runtime_invoke_check=
ed(_MonoMethod * method=3D0x00219710, void * obj=3D0x00000000, void * * par=
ams=3D0x0141f640, _MonoError * error=3D0x0141f6b8) Line 2980<span style=3D"=
white-space:pre">	</span>C</div><div>&gt;<span style=3D"white-space:pre">	<=
/span>mono-2.0-sgen.dll!do_exec_main_checked(_MonoMethod * method=3D0x00219=
710, _MonoArray * args=3D0x02c00290, _MonoError * error=3D0x0141f6b8) Line =
4697<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span style=
=3D"white-space:pre">	</span>mono-2.0-sgen.dll!mono_runtime_exec_main_check=
ed(_MonoMethod * method=3D0x00219710, _MonoArray * args=3D0x02c00290, _Mono=
Error * error=3D0x0141f6b8) Line 4798<span style=3D"white-space:pre">	</spa=
n>C</div><div>=C2=A0<span style=3D"white-space:pre">	</span>mono-2.0-sgen.d=
ll!mono_runtime_run_main_checked(_MonoMethod * method=3D0x00219710, int arg=
c=3D1, char * * argv=3D0x00171538, _MonoError * error=3D0x0141f6b8) Line 42=
26<span style=3D"white-space:pre">	</span>C</div><div>=C2=A0<span style=3D"=
white-space:pre">	</span>mono-2.0-sgen.dll!mono_jit_exec(_MonoDomain * doma=
in=3D0x00170900, _MonoAssembly * assembly=3D0x0016db00, int argc=3D1, char =
* * argv=3D0x00171538) Line 1027<span style=3D"white-space:pre">	</span>C</=
div><div>=C2=A0<span style=3D"white-space:pre">	</span>MonoTest.exe!main(in=
t argc=3D1, char * * argv=3D0x00171538) Line 65<span style=3D"white-space:p=
re">	</span>C++</div><div>=C2=A0<span style=3D"white-space:pre">	</span>Mon=
oTest.exe!invoke_main() Line 64<span style=3D"white-space:pre">	</span>C++<=
/div><div>=C2=A0<span style=3D"white-space:pre">	</span>MonoTest.exe!__scrt=
_common_main_seh() Line 253<span style=3D"white-space:pre">	</span>C++</div=
><div>=C2=A0<span style=3D"white-space:pre">	</span>MonoTest.exe!__scrt_com=
mon_main() Line 296<span style=3D"white-space:pre">	</span>C++</div><div>=
=C2=A0<span style=3D"white-space:pre">	</span>MonoTest.exe!mainCRTStartup()=
 Line 17<span style=3D"white-space:pre">	</span>C++</div><div>=C2=A0<span s=
tyle=3D"white-space:pre">	</span>kernel32.dll!@BaseThreadInitThunk@12 ()<sp=
an style=3D"white-space:pre">	</span>Unknown</div><div>=C2=A0<span style=3D=
"white-space:pre">	</span>ntdll.dll!__RtlUserThreadStart()<span style=3D"wh=
ite-space:pre">	</span>Unknown</div><div>=C2=A0<span style=3D"white-space:p=
re">	</span>ntdll.dll!__RtlUserThreadStart@8 ()<span style=3D"white-space:p=
re">	</span>Unknown</div></div><div><br></div></div>

--001a11424c1a7259320554a4f241--

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

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KTW9uby1saXN0
IG1haWxsaXN0ICAtICBNb25vLWxpc3RAbGlzdHMuZG90Lm5ldApodHRwOi8vbGlzdHMuZG90Lm5l
dC9tYWlsbWFuL2xpc3RpbmZvL21vbm8tbGlzdAo=

--===============3107064936797671287==--