pardeike/Harmony · error · Exception
Some method returned an unexpected result
Error message
Some method returned an unexpected result: {error} What it means
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.
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
Example fix
// before
class Patches { /* no TargetMethods, targets injected elsewhere */ }
// after
class Patches
{
static IEnumerable<MethodBase> TargetMethods()
{
var m = AccessTools.Method(typeof(Foo), "Bar");
if (m != null) yield return m;
}
} Defensive patterns
Strategy: validation
Validate before calling
Ensure a discoverable static TargetMethods() exists and returns a non-empty, null-free sequence before calling PatchAll.
Try / catch
try { harmony.PatchAll(); } catch (Exception e) when (e.Message.Contains("Some method returned an unexpected result")) { InspectBulkProviders(e); } Prevention
- Keep the standard 'static IEnumerable<MethodBase> TargetMethods()' signature intact
- Avoid renaming/hiding TargetMethods when subclassing Harmony processors
When it happens
Trigger: 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.
Common situations: Custom PatchTools/annotation setups; subclassed patch-class processors where the TargetMethods method is hidden or renamed; third-party frameworks wrapping Harmony.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- Method returned an unexpected result
- The type must declare an empty constructor (the constructor…
- position( ) + count( ) > buffer.Length( )
- Unbalanced exception markers – cannot rewrite.
- Multiple loaded HarmonySharedState types prevent safe…
AI-assisted analysis of pardeike/Harmony@e7872dc170 (2026-09-15).
Data as JSON: /api/errors/23b5fe0312fde17d.
Report an issue: GitHub.
Appendix: source
Thrown at Harmony/Public/PatchClassProcessor.cs:278
}
var result = new List<MethodBase>();
var targetMethods = RunMethod<HarmonyTargetMethods, IEnumerable<MethodBase>>(null, null);
if (targetMethods is object)
{
string error = null;
result = [.. targetMethods];
if (result is null)
error = "null";
else if (result.Any(m => m is null))
error = "some element was null";
if (error != null)
{
if (auxilaryMethods.TryGetValue(typeof(HarmonyTargetMethods), out var method))
throw new Exception($"Method {method.FullDescription()} returned an unexpected result: {error}");
else
throw new Exception($"Some method returned an unexpected result: {error}");
}
return result;
}
var targetMethod = RunMethod<HarmonyTargetMethod, MethodBase>(null, null, method => method is null ? "null" : null);
if (targetMethod is not null)
result.Add(targetMethod);
return result;
}
void ReportException(Exception exception, MethodBase original)
{
if (exception is null)
return;
if ((containerAttributes.debug ?? false) || Harmony.DEBUG)
{
_ = Harmony.VersionInfo(out var currentVersion);
View on GitHub (pinned to e7872dc170)