You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In specific cases, a System.NullReferenceException exception will be thrown from an ILHook's generated DMD (and sometimes FastDelegateInvokers.Invoke<...>) when using a custom delegate type for an instance method.
I got this to occur by doing the following:
In an assembly A, IL hook an arbitrary method and call ILCursor.EmitDelegate<CustomDelegate>(someInstanceMethod)
Call DetourModManager.Unload on A
Load a new assembly, B, that shares the same name and version with A
Hook the same method in the same way as A
This is when running Unity v4.6.3/Mono, targeting .NET Framework 3.5. Make sure that CustomDelegate is a delegate from your assembly, not e.g. Action or Func. Also make sure that someInstanceMethod is an instance method.
Example
delegatevoid A();stringWords="Hi";voidPrintWords(){
Console.WriteLine(Words);}voidEnable(){
IL.Room.Update +=MyILHook;}voidMyILHook(ILContextil){ILCursorcursor=new(il);
cursor.EmitDelegate<A>(PrintWords);// These also bug out because they compile as instance methods:// cursor.EmitDelegate<A>(() => Console.WriteLine(Words));// cursor.EmitDelegate<A>(() => Console.WriteLine("Hi"));}
Before step 2, this runs fine. When Room.Update is called, Hi gets printed to the console.
After step 4, however, whenever Room.Update is called, you'll instead get a nasty exception:
System.NullReferenceException: Object reference not set to an instance of an object
at (wrapper dynamic-method) Room.DMD<Room..Update> (Room) <0x0008c>
etc
The text was updated successfully, but these errors were encountered:
Description
In specific cases, a System.NullReferenceException exception will be thrown from an ILHook's generated DMD (and sometimes
FastDelegateInvokers.Invoke<...>
) when using a custom delegate type for an instance method.I got this to occur by doing the following:
A
, IL hook an arbitrary method and callILCursor.EmitDelegate<CustomDelegate>(someInstanceMethod)
DetourModManager.Unload
onA
B
, that shares the same name and version withA
A
This is when running Unity v4.6.3/Mono, targeting .NET Framework 3.5. Make sure that
CustomDelegate
is a delegate from your assembly, not e.g. Action or Func. Also make sure thatsomeInstanceMethod
is an instance method.Example
Before step 2, this runs fine. When
Room.Update
is called,Hi
gets printed to the console.After step 4, however, whenever
Room.Update
is called, you'll instead get a nasty exception:The text was updated successfully, but these errors were encountered: