{"record":{"id":"488a73e4e81e39f0","repo":"pardeike/Harmony","slug":"nameof-standin-nameof-standin-method-is-null","errorCode":null,"errorMessage":"{nameof(standin)}.{nameof(standin.method)} is NULL","messagePattern":"(.+?)\\.(.+?) is NULL","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Harmony/Internal/PatchFunctions.cs","lineNumber":55,"sourceCode":"\t\t\tif (replacement is null) throw new MissingMethodException($\"Cannot create replacement for {original.FullDescription()}\");\r\n\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tPatchTools.DetourMethod(original, replacement);\r\n\t\t\t}\r\n\t\t\tcatch (Exception ex)\r\n\t\t\t{\r\n\t\t\t\tthrow HarmonyException.Create(ex, finalInstructions);\r\n\t\t\t}\r\n\t\t\treturn replacement;\r\n\t\t}\r\n\r\n\t\tinternal static MethodInfo ReversePatch(HarmonyMethod standin, MethodBase original, MethodInfo postTranspiler)\r\n\t\t{\r\n\t\t\tif (standin is null)\r\n\t\t\t\tthrow new ArgumentNullException(nameof(standin));\r\n\t\t\tif (standin.method is null)\r\n\t\t\t\tthrow new ArgumentNullException(nameof(standin), $\"{nameof(standin)}.{nameof(standin.method)} is NULL\");\r\n\r\n\t\t\tvar debug = (standin.debug ?? false) || Harmony.DEBUG;\r\n\r\n\t\t\tvar transpilers = new List<MethodInfo>();\r\n\t\t\tif (standin.reversePatchType == HarmonyReversePatchType.Snapshot)\r\n\t\t\t{\r\n\t\t\t\tvar info = Harmony.GetPatchInfo(original);\r\n\t\t\t\ttranspilers.AddRange(GetSortedPatchMethods(original, [.. info.Transpilers], debug));\r\n\t\t\t}\r\n\t\t\tif (postTranspiler is not null) transpilers.Add(postTranspiler);\r\n\r\n\t\t\tvar emptyFix = new List<MethodInfo>();\r\n\t\t\tvar emptyInner = new List<Infix>();\r\n\t\t\tvar patcher = new MethodCreator(new MethodCreatorConfig(\r\n\t\t\t\tstandin.method,\r\n\t\t\t\toriginal,\r\n\t\t\t\temptyFix,\r\n\t\t\t\temptyFix,\r","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Internal/PatchFunctions.cs#L37-L73","documentation":"ReversePatch requires a stand-in HarmonyMethod whose .method property holds the method to reverse-patch. Harmony throws this ArgumentNullException (with a custom message) when HarmonyMethod instance is valid but its method field was never assigned.","triggerScenarios":"Calling PatchFunctions.ReversePatch (e.g. harmony.CreateReversePatcher or ReversePatch) with a HarmonyMethod built without a MethodInfo, e.g. new HarmonyMethod() with no method argument, or one deserialized/copied with method lost.","commonSituations":"Creating a HarmonyMethod from a patch class annotation where the info field wasn't bound, copying HarmonyMethod properties between instances, or calling CreateReversePatcher with a HarmonyMethod(null).","solutions":["Pass a valid MethodInfo when constructing the HarmonyMethod: new HarmonyMethod(AccessTools.Method(typeof(Target), nameof(Target.Run))).","Check standin.method before calling and construct the HarmonyMethod from the correct method.","If copying a HarmonyMethod, ensure the method field is carried over (clone with new HarmonyMethod(methodInfo))."],"exampleFix":"// before\nvar standin = new HarmonyMethod(); // method is null\nharmony.CreateReversePatcher(original, standin);\n\n// after\nvar standin = new HarmonyMethod(AccessTools.Method(typeof(MyPatch), nameof(MyPatch.Snapshot)));\nharmony.CreateReversePatcher(original, standin);","handlingStrategy":"type-guard","validationCode":"if (standin is null || standin.method is null)\n    throw new InvalidOperationException(\"CreateReversePatcher requires HarmonyMethod with a valid method\");","typeGuard":"static bool IsValidStandin(HarmonyMethod hm) => hm?.method is MethodInfo;","tryCatchPattern":"try { var rp = harmony.CreateReversePatcher(original, standin); rp.Patch(); }\ncatch (ArgumentNullException ex)\n{ Logger.Error($\"ReversePatch stand-in invalid: {ex.Message}\"); }","preventionTips":["Always construct stand-in HarmonyMethod from a real MethodInfo, never empty constructors.","When copying HarmonyMethod instances, carry the method field explicitly.","Validate standin.method right before CreateReversePatcher in helper wrappers."],"tags":["harmony","reverse-patch","null-argument"],"backgroundTag":"null-argument","analyzedSha":"e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c","analyzedAt":"2026-09-15T22:47:11.550Z","contentChangedAt":"2026-09-15T22:47:11.550Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}