pardeike / Harmony

A library for patching, replacing and decorating .NET and Mono methods during runtime
https://www.patreon.com/pardeike
MIT License
5.28k stars 492 forks source link

Odd conversion exception exception #128

Closed FrodoOf9Fingers closed 5 years ago

FrodoOf9Fingers commented 6 years ago

[HugsLib][ERR] Failed to apply Harmony patches for HugsLib.amnesia. Exception was: System.Exception: Exception from HarmonyInstance "HugsLib.amnesia" ---> System.ArgumentException: Object type System.Collections.Generic.List1[Harmony.ILCopying.ExceptionBlock] cannot be converted to target type: System.Collections.Generic.List1[Harmony.ILCopying.ExceptionBlock] Parameter name: val at System.Reflection.MonoField.SetValue (System.Object obj, System.Object val, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 at Harmony.Traverse.SetValue (System.Object value) [0x00000] in <filename unknown>:0 at Harmony.CodeTranspiler+<>c__DisplayClass4_0.<ConvertInstruction>b__0 (System.String name, Harmony.Traverse trvFrom, Harmony.Traverse trvDest) [0x00000] in <filename unknown>:0 at Harmony.Traverse+<>c__DisplayClass35_0.<IterateFields>b__0 (System.String f) [0x00000] in <filename unknown>:0 at System.Collections.Generic.List1[System.String].ForEach (System.Action1 action) [0x00000] in <filename unknown>:0 at Harmony.Traverse.IterateFields (System.Object source, System.Object target, System.Action3 action) [0x00000] in :0 at Harmony.CodeTranspiler.ConvertInstruction (System.Type type, System.Object op, System.Collections.Generic.Dictionary2& unassigned) [0x00000] in <filename unknown>:0 at Harmony.CodeTranspiler.ConvertInstructionsAndUnassignedValues (System.Type type, IEnumerable enumerable, System.Collections.Generic.Dictionary2& unassignedValues) [0x00000] in :0 at Harmony.CodeTranspiler.ConvertToGeneralInstructions (System.Reflection.MethodInfo transpiler, IEnumerable enumerable, System.Collections.Generic.Dictionary2& unassignedValues) [0x00000] in <filename unknown>:0 at Harmony.CodeTranspiler+<>c__DisplayClass10_0.<GetResult>b__0 (System.Reflection.MethodInfo transpiler) [0x00000] in <filename unknown>:0 at System.Collections.Generic.List1[System.Reflection.MethodInfo].ForEach (System.Action1 action) [0x00000] in <filename unknown>:0 at Harmony.CodeTranspiler.GetResult (System.Reflection.Emit.ILGenerator generator, System.Reflection.MethodBase method) [0x00000] in <filename unknown>:0 at Harmony.ILCopying.MethodBodyReader.FinalizeILCodes (System.Collections.Generic.List1 transpilers, System.Collections.Generic.List1 endLabels, System.Collections.Generic.List1 endBlocks) [0x00000] in :0 at Harmony.ILCopying.MethodCopier.Finalize (System.Collections.Generic.List1 endLabels, System.Collections.Generic.List1 endBlocks) [0x00000] in :0 at Harmony.MethodPatcher.CreatePatchedMethod (System.Reflection.MethodBase original, System.String harmonyInstanceID, System.Collections.Generic.List1 prefixes, System.Collections.Generic.List1 postfixes, System.Collections.Generic.List1 transpilers) [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at Harmony.MethodPatcher.CreatePatchedMethod (System.Reflection.MethodBase original, System.String harmonyInstanceID, System.Collections.Generic.List1 prefixes, System.Collections.Generic.List1 postfixes, System.Collections.Generic.List1 transpilers) [0x00000] in :0 at Harmony.PatchFunctions.UpdateWrapper (System.Reflection.MethodBase original, Harmony.PatchInfo patchInfo, System.String instanceID) [0x00000] in :0 at Harmony.PatchProcessor.Patch () [0x00000] in :0 at Harmony.HarmonyInstance.b__7_0 (System.Type type) [0x00000] in :0 at Harmony.CollectionExtensions.Do[Type] (IEnumerable1 sequence, System.Action1 action) [0x00000] in :0 at Harmony.HarmonyInstance.PatchAll (System.Reflection.Assembly assembly) [0x00000] in :0 at HugsLib.ModBase.ApplyHarmonyPatches () [0x00000] in :0 Verse.Log:Error(String, Boolean) HugsLib.Utils.ModLogger:Error(String, Object[]) HugsLib.ModBase:ApplyHarmonyPatches() HugsLib.HugsLibController:EnumerateChildMods() HugsLib.HugsLibController:LoadReloadInitialize() Verse.LongEventHandler:RunEventFromAnotherThread(Action) Verse.LongEventHandler:m__1() `

This happens when trying to apply two patches to the same method (I believe). My game mod is conflicting with another game mod that should also be using Harmony (Rimworld, AlienRace v2. Target method being found with: [HarmonyPatch(typeof(PawnGenerator), "GenerateTraits", new Type[] { typeof(Pawn), typeof(PawnGenerationRequest) })]

pardeike commented 6 years ago

What are the Harmony versions that are patching that method? Which comes first?