Assembly.GetExecutingAssembly () not working in inline mono?

I am trying to embed mono in a C ++ executable and mono crashes Assembly.GetExecutingAssembly. Any idea on what I missed?

EDIT: 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_fbmonoengine    = mono_domain_assembly_open (domain, "ClassLibrary1.dll");  
    MonoImage* _image_fbmonoengine      = mono_assembly_get_image (_assembly_fbmonoengine);
    MonoClass* klass = mono_class_from_name(_image_fbmonoengine, "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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ClassLibrary1
{
    public class Class1
    {
        public static void Test()
        {
            Assembly.GetExecutingAssembly();
        }
    }
}

      

Mistake:

Unhandled exception at 0x65ad2148 in EmbeddedMonoTest.exe: 0xC0000005: Access violation reading location 0x`00000008.

      

+3


source to share


1 answer


You are not doing any assembly in your program, so ExecutingAssembly makes no sense in this context (although an error is better needed). You need to provide a regular static Main () point in the assembly and execute it with mono_runtime_exec_main ().



+2


source







All Articles