卸载域退出程序

问题描述


我在Mono-Embedded中卸载应用程序域时遇到问题,
应用程序被单声道关闭并在日志中显示消息(请参见下文)。
删除mono_jit_exec可以修复该问题,但显然不会调用main。
我的猜测是mono_jit_exec需要进行一些清理,但文档中没有提到该函数的任何内容。
Github Issue 8697中写道:“ SGen中的崩溃表明您破坏了托管堆,通常是绑定时出错。”但我看不到它可能在哪里破坏堆。
提前致谢

单版本:6.12.0 (Visual Studio built mono)

日志:
Assertion: should not be reached at d:\j\workspace\build-package-win-mono\2020-02\mono\sgen\sgen-scan-object.h:91

CS

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine("Hello,world!");
        }
    }
}

C


//init jit
{
    mono_config_parse(NULL);
    mono_set_dirs("Mono/lib","Mono/etc");

    m_domain = mono_jit_init(name);
    if (m_domain == nullptr) {
        return false;
    }

    mono_thread_set_main(mono_thread_current());

    //set output streams and error streams
    mono_trace_set_log_handler(MonoLogCallbackFunction,nullptr);
    mono_trace_set_print_handler(MonoPrintCallbackFunction);
    mono_trace_set_printerr_handler(MonoPrintCallbackFunction);
}

//load programm in seperate domain
{
    //Create Domain
    m_domain2 = mono_domain_create_appdomain((char*)"AppDomain",NULL);
    mono_thread_attach(m_domain2);
    mono_domain_set(m_domain2,false);

    //load assembly
    //file = correct path to exe. Command for compile: "mcs main.cs -out:main.exe"
    m_assembly = mono_domain_assembly_open(m_domain2,file);

    //run main
    //argc = 1
    //argv = const char** = { "FolderPath of exe" }
    mono_jit_exec(m_Domain2,m_assembly,argc,argv); //removing this call fixes the problem

    //unload domain
    MonoDomain* old_domain = mono_domain_get();
    if (old_domain == m_domain2 && old_domain != mono_get_root_domain()) {
        mono_domain_set(mono_get_root_domain(),false);
    }
    mono_domain_unload(m_domain2); //<- here is the exit called

}

//clean up
{
    mono_jit_cleanup(m_domain);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)