-
-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patch on .net 7&8 throw TypeLoadException while debugging #585
Comments
Can you explain a little bit more? Please tell me how you debug your code, and if you use Harmony in the same project or on a different DLL so I can reproduce your case. I just need more details. |
here is sample project. i use rider open it and start with debug. and then, |
if you just run ConsoleApp1, it work well. |
I can confirm it with Visual Studio, Harmony 2.3 and net8 locally, ping @nike4613 using HarmonyLib;
namespace ClassLibrary1;
public class Class1
{
public static void A()
{
Console.WriteLine("Class1 A");
}
}
public class Patch
{
private static Harmony _harmony = new Harmony("Patch");
public static void Do()
{
//var action = Class1.A;
//_harmony.Patch(action.Method, postfix: new HarmonyMethod(Hook));
var mA = SymbolExtensions.GetMethodInfo(() => Class1.A());
var mHook = SymbolExtensions.GetMethodInfo(() => Patch.Hook());
_harmony.Patch(mA, postfix: new HarmonyMethod(mHook));
}
public static void Hook()
{
Console.WriteLine("Hook");
}
}
|
That looks like a legacy stacktrace, and that supports neither .NET 7 nor .NET 8.
|
Here is a more simpler example: using HarmonyLib;
namespace TestingNet8
{
internal class Program
{
static void Main(string[] args)
{
var harmony = new Harmony("test");
var original = SymbolExtensions.GetMethodInfo(() => new Test().HelloWorld());
var postfix = SymbolExtensions.GetMethodInfo(() => Patch.Postfix());
Console.WriteLine("Start");
harmony.Patch(original, postfix: new HarmonyMethod(postfix));
Console.WriteLine("Stop");
}
}
public class Test
{
public void HelloWorld()
{
Console.WriteLine("Hello, World!");
}
}
public class Patch
{
public static void Postfix()
{
Console.WriteLine("Patched!");
}
}
} In a net7 project it runs Debug+Release. In the same but switched to net8 it has an exception (either Debug or Release) |
So how did that come into play with a reference to the nuget package Lib.Harmony 2.3? Lets continue this on the discord. |
Ok, after investigating this I found that my Visual Studio had somehow the wrong (old?) version of Harmony 2.3 in the nuget cache. Not really sure why but after removing all cached versions in After that, your project runs ands debugs fine. |
I tested in vs2022, it work. but in rider was same issue. here is debug output
load module:
|
We are working on an update to Harmony. We can see if it fixes this issue. |
I found that , when |
This should be fixed with the 2.3.1.1 release I just made |
I had the same problem on Rider 2023.3 with the new 2.3.1.1 version. The problem didn't happen on Visual Studio 2022. "Supress JIT optimizations on module load (Managed only)" was disabled by default. @zznty suggested on Discord to install |
I have the same issue in Rider with Lib.Harmony 2.3.3 |
Try disable |
|
J'ai également eu ce problème lors de l'injection dans un programme Comment devrais - je résoudre le Framework de net7.0 utilisé lors du programme cible j'ai également essayé de désactiver JIT, mais je me trompe quand même |
Describe the bug
when start debugger , patch will throw TypeLoadException:
if without debugger, program work well.
Runtime environment (please complete the following information):
The text was updated successfully, but these errors were encountered: