[Mono-list] Mono CSharp Evaluator : creating two Action<object> via two distinct Run() crashes

Nelson Cabral nelson.cabral at gmail.com
Mon Feb 18 17:38:59 UTC 2013


I'm trying to embed mono in a c++ executable, and mono crashes on the
second evaluator.Run(..) as below. Any idea of what I missed ?

Using mono 3.0.3.

EmbeddedMonoTest.cpp

// EmbeddedMonoTest.cpp : Defines the entry point for the console application.//
#include "stdafx.h"#include <mono/metadata/debug-helpers.h>#include
<mono/metadata/exception.h>#include <mono/jit/jit.h>#include
<mono/metadata/assembly.h>int _tmain(int argc, _TCHAR* argv[]){
    MonoDomain* domain = mono_jit_init_version ("ClassLibrary1", "v4.0.30319");
    MonoAssembly* assembly  = mono_domain_assembly_open (domain,
"ClassLibrary1.dll");
    mono_assembly_get_image(mono_domain_assembly_open (domain,
"Mono.CSharp.dll"));
    MonoImage* image = mono_assembly_get_image (assembly);
    MonoClass* klass = mono_class_from_name(image, "ClassLibrary1", "Class1");
    MonoMethod* test = mono_class_get_method_from_name(klass, "Test", 0);
    mono_runtime_invoke(test, NULL, NULL, NULL);
    return 0;}

Class1.cs

using System;using System.Reflection;using Mono.CSharp;
namespace ClassLibrary1{
    public class Class1
    {
        public static void Test()
        {

            var assembly = Assembly.GetAssembly(typeof(Class1));

            CompilerSettings settings = new CompilerSettings();
            ReportPrinter printer = new ConsoleReportPrinter();
            CompilerContext context = new CompilerContext(settings, printer);
            Evaluator evaluator = new Evaluator(context);
            evaluator.ReferenceAssembly(assembly);
            evaluator.Run("using System; using ClassLibrary1;");
            evaluator.Run("Action<object> action = args => {{
'x'.ToString(); }}; ");
            evaluator.Run("Action<object> b = args => {{ 'x'.ToString(); }}; ");
        }
    }}

The error :

Unhandled exception at 0x0274b00d in EmbeddedMonoTest.exe: 0xC0000005:
Access violation reading location 0x00000000.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20130218/f8f2b658/attachment-0001.html>


More information about the Mono-list mailing list