BepInEx / HarmonyX

Harmony built on top of MonoMod.RuntimeDetours with additional features
MIT License
374 stars 44 forks source link

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

Open Ribosome2 opened 1 year ago

Ribosome2 commented 1 year ago

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()

bbsuuo commented 1 year ago

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.