-
Notifications
You must be signed in to change notification settings - Fork 122
Injection failed: mono_class_from_name() returned NULL #11
Description
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 🤷