Skip to content
This repository was archived by the owner on Oct 28, 2020. It is now read-only.
This repository was archived by the owner on Oct 28, 2020. It is now read-only.

Injection failed: mono_class_from_name() returned NULL #11

@PandaSt0rm

Description

@PandaSt0rm

So I've come across a rather interesting issue, and I have no idea how to actually resolve it.
Essentially I've just been testing injecting into a game process, and it was working fine initially, however after a few loads and unloads I started getting a mono_class_from_name error.

I've tested with a new project, still getting the same error.

This is the 'loader' class

using UnityEngine;

namespace Test
{
    public class Loader
    {
        public static GameObject _Load;

        public static void Load()
        {
            _Load = new GameObject();
            // Add component classes to load into the game
            _Load.AddComponent<Main>();
            Object.DontDestroyOnLoad(_Load);
        }

        public static void Unload()
        {
            Object.Destroy(_Load);
        }

    }
}

And what happens when I attempt to inject (same result for either GUI or Console)

.\smi.exe inject -p DEMO -a .\Test.dll -n Test -c Loader -m Load                                                                         Failed to inject assembly: SharpMonoInjector.InjectorException: mono_class_from_name() returned NULL
   at SharpMonoInjector.Injector.ThrowIfNull(IntPtr ptr, String methodName)
   at SharpMonoInjector.Injector.GetClassFromName(IntPtr image, String namespace, String className)
   at SharpMonoInjector.Injector.Inject(Byte[] rawAssembly, String namespace, String className, String methodName)
   at SharpMonoInjector.Console.Program.Inject(Injector injector, CommandLineArguments args)

Something I have noticed is that if I name the Load method as Init, it """works""" (nothing is actually injected but smi reports success).

In fact as I was typing this out it started working again (using Load as the class name)

.\smi.exe inject -p DEMO -a .\Test.dll -n Test -c Loader -m Load                                                                         Test.dll: 0x00000193B4DDE5F0

Could .NET be caching something, because I was trying to load/unload immediately before, but now DEMO was closed for around 10 minutes before I attempted the same command on the same dll, and it worked 🤷

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions