Closed 2767mr closed 10 months ago
Any ideas @nike4613 ?
The interface method being in the stack trace is a bit sus, but I'd need to look at it in WinDbg to understand the problem. (Also, isn't 2.2.2 pre-MM.Core?)
Yes my bad. This should be tested with master to verify MonoMod.Core functionality. I thought you might chime in on the general usage of an interface here.
I can't even guess why its happening, but it might have to do with using a version that doesn't support the runtime.
I tested with LinqPad 7 and NET7 and I cannot reproduce:
void Main()
{
Harmony.VersionInfo(out var version);
Console.WriteLine(version);
Console.WriteLine(Environment.Version);
var harmony = new Harmony("test");
var info = typeof(Foo).GetMethod(nameof(Foo.Test)) ?? throw new Exception("Could not find method info");
var prefixInfo = typeof(Example).GetMethod(nameof(Example.Prefix)) ?? throw new Exception("Could not find Prefix method info");
harmony.Patch(info, new HarmonyMethod(prefixInfo));
var s = ((Bar)new Foo()).Test();
Console.WriteLine(s);
}
class Example
{
public static void Prefix()
{
Console.WriteLine("Prefix");
}
}
public interface Bar
{
string Test();
}
public class Foo : Bar
{
public string Test()
{
return "Test Result";
}
}
prints
2.2.2.0
7.0.10
Prefix
Test Result
I also tested with prerelease and it prints:
2.3.0.0
7.0.10
Prefix
Test Result
I discovered that the crash only happens when I use the Visual Studio (2022, community, latest) debugger. However, on my machine dotnet run
still prints a wrong result:
2.2.2.0
7.0.10
Test Result
I made a Dockerfile to (hopefully) reproduce the issue:
Dockerfile.txt
docker build -t bug .
docker run --rm -it bug
Here is also a .NET Fiddle
Prerelease does work properly. Will use that as a workaround for now.
When accessing a patched method through an interface, it will cause an internal CLR error. This only happens with .NET 7 or above.
To reproduce:
Crash
``` Fatal error. Internal CLR error. (0x80131506) at Bar.Test() at Program.<Harmony debug log
``` ### Harmony id=test, version=2.2.2.0, location=C:\path\to\project\bin\Debug\net7.0\0Harmony.dll, env/clr=7.0.5, platform=Win32NT, ptrsize:runtime/env=8/Bits64, Windows ### Started from static System.Void Program::<Runtime environment: