简体   繁体   中英

mono_class_from_name_case returns nullptr

mono_class_from_name_case returns nullptr and i found no way to get more information why, and the mono documentation is very basic. My question is, i think i am missing something, is there a method to "link" the two assemblys together?, is that even needed?, why is the class showing up in the metadata but not accessable via get class?
I get the name and namespace through the metadata interface and they are valid strings. The dlls are compiled without any warnings/errors. Beetween the open of the assambly and the metadata access is no other operation. The code is first executed for base.dll then for content.dll. Both are in the same Domain, but different Assemblys and images.

Things i noticed:
Removing the base class in Slime "fixes" it. <- maybe missing a reference to base.dll?
It still does not work, when making the base not abstract/without any virtual method
Changing from mono_class_from_name_case to mono_class_from_name has the same behavior.

C++ Code:

    //metadata.getRaw returns a MonoImage* loaded with mono_domain_assembly_open & mono_assembly_get_image, the base dll is loaded first
    const MonoTableInfo* table_info = mono_image_get_table_info(metadata.GetRaw(), MONO_TABLE_TYPEDEF);
    int rows = mono_table_info_get_rows(table_info);


    for (int i = 0; i < rows; i++)
    {
        MonoClass* _class = nullptr;
        uint32_t cols[MONO_TYPEDEF_SIZE];
        mono_metadata_decode_row(table_info, i, cols, MONO_TYPEDEF_SIZE);
        const char* name = mono_metadata_string_heap(metadata.GetRaw(), cols[MONO_TYPEDEF_NAME]);
        const char* name_space = mono_metadata_string_heap(metadata.GetRaw(), cols[MONO_TYPEDEF_NAMESPACE]);

        //this returns nullptr for a valid class, i think the base dll is not loaded
        _class = mono_class_from_name_case(metadata.GetRaw(), name_space, name);

        //this does happen...
        if (_class == nullptr) {
            continue;
        }

    }

The two involved DLLs:

Base.dll

csc.exe -target:library -nologo -optimize+ -debug- -out:Base.dll Item.cs
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Base
{

    public abstract class Item
    {
        public Item()
        {

        }

        public abstract bool init();
        public abstract void release();

    }

}

Content.dll

csc.exe -target:library -nologo -optimize+ -debug- -reference:Base.dll -out:Content.dll Slime.cs
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Content{
    
    public class Slime : Base.Item
    {
        public Slime()
        {

        }

        public override bool init()
        {
            return true;
        }
        public override void release()
        {

        }


    }

    
}

I found the "error" there is a difference beetween mono_assembly_load and mono_domain_assembly_open. With mono_assembly_load it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM