HarmonyX icon indicating copy to clipboard operation
HarmonyX copied to clipboard

The test code works in C# console app,but not in Unity

Open Ribosome2 opened this issue 1 year ago • 1 comments

image first I put the dlls in Unity's plugin folder:

And then I copy paste the code in C# console app image

And I got this error: System.TypeInitializationException: An exception was thrown by the type initializer for HarmonyLib.AccessTools ---> System.TypeInitializationException: An exception was thrown by the type initializer for MonoMod.Utils.DynamicMethodDefinition ---> System.TypeInitializationException: An exception was thrown by the type initializer for MonoMod.Utils.ReflectionHelper ---> System.NullReferenceException: Object reference not set to an instance of an object at MonoMod.Utils.ReflectionHelper..cctor () [0x00000] in :0 --- End of inner exception stack trace --- at MonoMod.Utils.DynamicMethodDefinition..cctor () [0x00000] in :0 --- End of inner exception stack trace --- at HarmonyLib.MethodInvoker.GetHandler (System.Reflection.MethodInfo methodInfo, Boolean directBoxValueAccess) [0x00000] in :0 at HarmonyLib.AccessTools..cctor () [0x00000] in :0 --- End of inner exception stack trace --- at HarmonyLib.Internal.RuntimeFixes.StackTraceFixes.Install () [0x00000] in :0 UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes()

Ribosome2 avatar Mar 31 '23 02:03 Ribosome2

It is caused by inconsistent target frameworks. It seems like you are using a target framework that is not supported by Unity. When developing plugins, it is advisable to use .NET 3.5 as the target framework.

bbsuuo avatar May 30 '23 15:05 bbsuuo