© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
2 replies
GigaElmo

Mono vm not allowing me to call the constructor on a class that inherits from another class

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Frekit;

namespace CSAssembly
{
    public class Vinny : Behaviour
    {
        public void Awake()
        {
            Console.WriteLine("Vinny woke up");
        }
        private void SayHi()
        {
            Console.WriteLine("Hi");
        }
        public Vinny()
        {
            Console.WriteLine("Vinny has been summoned");
        }
    }
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Frekit;

namespace CSAssembly
{
    public class Vinny : Behaviour
    {
        public void Awake()
        {
            Console.WriteLine("Vinny woke up");
        }
        private void SayHi()
        {
            Console.WriteLine("Hi");
        }
        public Vinny()
        {
            Console.WriteLine("Vinny has been summoned");
        }
    }
}
this is the class im trying to instanciate
static void init() {
    std::string libPath = (std::filesystem::current_path() / "lib").string();
    std::string etcPath = (std::filesystem::current_path() / "etc").string();

    mono_set_dirs(libPath.c_str(), etcPath.c_str());
    domain = mono_jit_init("GameLib");

    mono_add_internal_call("Frekit.Behaviour::AddCalls", addCalls);
    mono_add_internal_call("Frekit.Behaviour::RemoveCalls", removeCalls);
    mono_add_internal_call("Frekit.Module::GetInstanceID", getInstanceID);


    coreAssembly = mono_domain_assembly_open(domain, "bin/Frekit.Core.dll");
    assembly = mono_domain_assembly_open(domain, "bin/CSAssembly.dll");

    coreImage = mono_assembly_get_image(coreAssembly);
    image = mono_assembly_get_image(assembly);

    MonoClass* vinnyClass = mono_class_from_name(image, "CSAssembly", "Vinny");
    MonoClass* behaviourClass = mono_class_from_name(coreImage, "Frekit", "Behaviour");
    MonoClass* moduleClass = mono_class_from_name(coreImage, "Frekit", "Module");
    MonoObject* vinny = mono_object_new(domain, vinnyClass); 
    mono_runtime_object_init(vinny); // Throws error, something about null method info
    mono_runtime_invoke(earlyBirds[*(uint64_t*)mono_object_unbox(getInstanceID(vinny))], vinny, NULL, NULL);
    return;
}
static void init() {
    std::string libPath = (std::filesystem::current_path() / "lib").string();
    std::string etcPath = (std::filesystem::current_path() / "etc").string();

    mono_set_dirs(libPath.c_str(), etcPath.c_str());
    domain = mono_jit_init("GameLib");

    mono_add_internal_call("Frekit.Behaviour::AddCalls", addCalls);
    mono_add_internal_call("Frekit.Behaviour::RemoveCalls", removeCalls);
    mono_add_internal_call("Frekit.Module::GetInstanceID", getInstanceID);


    coreAssembly = mono_domain_assembly_open(domain, "bin/Frekit.Core.dll");
    assembly = mono_domain_assembly_open(domain, "bin/CSAssembly.dll");

    coreImage = mono_assembly_get_image(coreAssembly);
    image = mono_assembly_get_image(assembly);

    MonoClass* vinnyClass = mono_class_from_name(image, "CSAssembly", "Vinny");
    MonoClass* behaviourClass = mono_class_from_name(coreImage, "Frekit", "Behaviour");
    MonoClass* moduleClass = mono_class_from_name(coreImage, "Frekit", "Module");
    MonoObject* vinny = mono_object_new(domain, vinnyClass); 
    mono_runtime_object_init(vinny); // Throws error, something about null method info
    mono_runtime_invoke(earlyBirds[*(uint64_t*)mono_object_unbox(getInstanceID(vinny))], vinny, NULL, NULL);
    return;
}
and this is how im trying to do it from cpp
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ ✅ How to call a specific attribute from a getter class to another class
C#CC# / help
3y ago
Call a property from a class that is within a class
C#CC# / help
3y ago
Calling a method from static class which also inherits from a non static class
C#CC# / help
3y ago
How do I call the constructor of a parent class?
C#CC# / help
3y ago