{"record":{"id":"23b5fe0312fde17d","repo":"pardeike/Harmony","slug":"some-method-returned-an-unexpected-result-error","errorCode":null,"errorMessage":"Some method returned an unexpected result: {error}","messagePattern":"Some method returned an unexpected result: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Harmony/Public/PatchClassProcessor.cs","lineNumber":278,"sourceCode":"\t\t\t}\r\n\r\n\t\t\tvar result = new List<MethodBase>();\r\n\r\n\t\t\tvar targetMethods = RunMethod<HarmonyTargetMethods, IEnumerable<MethodBase>>(null, null);\r\n\t\t\tif (targetMethods is object)\r\n\t\t\t{\r\n\t\t\t\tstring error = null;\r\n\t\t\t\tresult = [.. targetMethods];\r\n\t\t\t\tif (result is null)\r\n\t\t\t\t\terror = \"null\";\r\n\t\t\t\telse if (result.Any(m => m is null))\r\n\t\t\t\t\terror = \"some element was null\";\r\n\t\t\t\tif (error != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (auxilaryMethods.TryGetValue(typeof(HarmonyTargetMethods), out var method))\r\n\t\t\t\t\t\tthrow new Exception($\"Method {method.FullDescription()} returned an unexpected result: {error}\");\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tthrow new Exception($\"Some method returned an unexpected result: {error}\");\r\n\t\t\t\t}\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\r\n\t\t\tvar targetMethod = RunMethod<HarmonyTargetMethod, MethodBase>(null, null, method => method is null ? \"null\" : null);\r\n\t\t\tif (targetMethod is not null)\r\n\t\t\t\tresult.Add(targetMethod);\r\n\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tvoid ReportException(Exception exception, MethodBase original)\r\n\t\t{\r\n\t\t\tif (exception is null)\r\n\t\t\t\treturn;\r\n\t\t\tif ((containerAttributes.debug ?? false) || Harmony.DEBUG)\r\n\t\t\t{\r\n\t\t\t\t_ = Harmony.VersionInfo(out var currentVersion);\r","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Public/PatchClassProcessor.cs#L260-L296","documentation":"Same validation as the HarmonyTargetMethods failure, but thrown when no HarmonyTargetMethods auxiliary method could be identified in the class, so Harmony cannot name the culprit. It still signals that some bulk-target provider returned null or contained null/empty results.","triggerScenarios":"GetBulkMethods validation fails (result null, empty, or containing nulls) while the auxilaryMethods dictionary has no entry for typeof(HarmonyTargetMethods), e.g. when targets come from custom annotation plumbing rather than a discoverable TargetMethods method.","commonSituations":"Custom PatchTools/annotation setups; subclassed patch-class processors where the TargetMethods method is hidden or renamed; third-party frameworks wrapping Harmony.","solutions":["Ensure a static TargetMethods() method exists and is discoverable on the patch class (public/static, correct return type)","Fix the same underlying issue: make the provider return a non-empty sequence without null elements","If using custom plumbing, make sure the method is registered in auxilaryMethods so failures are attributable"],"exampleFix":"// before\nclass Patches { /* no TargetMethods, targets injected elsewhere */ }\n// after\nclass Patches\n{\n    static IEnumerable<MethodBase> TargetMethods()\n    {\n        var m = AccessTools.Method(typeof(Foo), \"Bar\");\n        if (m != null) yield return m;\n    }\n}","handlingStrategy":"validation","validationCode":"Ensure a discoverable static TargetMethods() exists and returns a non-empty, null-free sequence before calling PatchAll.","typeGuard":null,"tryCatchPattern":"try { harmony.PatchAll(); } catch (Exception e) when (e.Message.Contains(\"Some method returned an unexpected result\")) { InspectBulkProviders(e); }","preventionTips":["Keep the standard 'static IEnumerable<MethodBase> TargetMethods()' signature intact","Avoid renaming/hiding TargetMethods when subclassing Harmony processors"],"tags":["target-methods","unattributed-failure","harmony"],"backgroundTag":"empty-result-set","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"}