pardeike/Harmony · error · ArgumentException

Cannot not find method for type

Error message

Cannot not find method for type {methodType} and name {methodName} and parameters {argumentTypes?.Description()}

What it means

This HarmonyMethod constructor builds a patch descriptor from a type + method name (+ optional argument types). It resolves via AccessTools.Method and throws ArgumentException when no matching method exists, so the descriptor can never be created.

Solutions

  1. Correct the method name and verify with AccessTools.Method(methodType, methodName, argumentTypes)
  2. Provide exact argumentTypes to match the intended overload
  3. Construct the HarmonyMethod from a MethodInfo (new HarmonyMethod(mi)) obtained with your own null-checked lookup
  4. Version-check the target assembly at startup and disable/log when the method signature changed

Example fix

// before
var patch = new HarmonyMethod(typeof(Game), "ApllyDamage");
// after
var mi = AccessTools.Method(typeof(Game), nameof(Game.ApplyDamage));
if (mi is null) throw new InvalidOperationException("Game.ApplyDamage missing");
var patch = new HarmonyMethod(mi);
Defensive patterns

Strategy: validation

Validate before calling

var mi = AccessTools.Method(methodType, methodName, argumentTypes);
if (mi is null) throw new InvalidOperationException($"Patch target {methodType}.{methodName} not found");
var patch = new HarmonyMethod(mi);

Type guard

bool IsPatchable(Type t, string n) => AccessTools.Method(t, n) is not null;

Try / catch

try { patch = new HarmonyMethod(methodType, methodName, argumentTypes); } catch (ArgumentException ex) { log.Error($"Patch target missing: {methodType}.{methodName}", ex); throw; }

Prevention

When it happens

Trigger: new HarmonyMethod(typeof(T), "MethodName") where MethodName is missing/renamed, or the parameters array filters out every overload; also when the method is defined on a base type not matched by the resolver.

Common situations: Target library refactor renamed or removed the patched method; attribute-style patches converted to manual HarmonyMethod instances after an update; typos and case mismatches in the method name.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of pardeike/Harmony@e7872dc170 (2026-09-15). Data as JSON: /api/errors/8be796a8247f16a0. Report an issue: GitHub.

Appendix: source

Thrown at Harmony/Public/HarmonyMethod.cs:134

		/// <param name="priority">The patch <see cref="Priority"/></param>
		/// <param name="before">A list of harmony IDs that should come after this patch</param>
		/// <param name="after">A list of harmony IDs that should come before this patch</param>
		/// <param name="debug">Set to true to generate debug output</param>
		///
		public HarmonyMethod(Delegate @delegate, int priority = -1, string[] before = null, string[] after = null, bool? debug = null)
			: this(@delegate.Method, priority, before, after, debug)
		{ }

		/// <summary>Creates a patch from a given method</summary>
		/// <param name="methodType">The patch class/type</param>
		/// <param name="methodName">The patch method name</param>
		/// <param name="argumentTypes">The optional argument types of the patch method (for overloaded methods)</param>
		///
		public HarmonyMethod(Type methodType, string methodName, Type[] argumentTypes = null)
		{
			var result = AccessTools.Method(methodType, methodName, argumentTypes);
			if (result is null)
				throw new ArgumentException($"Cannot not find method for type {methodType} and name {methodName} and parameters {argumentTypes?.Description()}");
			ImportMethod(result);
		}

		/// <summary>Gets the names of all internal patch info fields</summary>
		/// <returns>A list of field names</returns>
		///
		public static List<string> HarmonyFields()
		{
			return [.. AccessTools
				.GetFieldNames(typeof(HarmonyMethod))
				.Where(s => s != "method")];
		}

		/// <summary>Merges annotations</summary>
		/// <param name="attributes">The list of <see cref="HarmonyMethod"/> to merge</param>
		/// <returns>The merged <see cref="HarmonyMethod"/></returns>
		///
		public static HarmonyMethod Merge(List<HarmonyMethod> attributes)

View on GitHub (pinned to e7872dc170)