pardeike/Harmony · error · ArgumentException

No method found for , parameters= , generics=

Error message

No method found for {typeColonMethodname}, parameters={parameters.Description()}, generics={generics.Description()}

What it means

Like the Type-based overload, this CodeInstruction.Call overload parses a 'TypeFullName:MethodName' string, resolves it with AccessTools.Method, and throws ArgumentException if the resolution yields null after applying the parameters/generics filters.

Solutions

  1. Fix the typeColonMethodname string to the exact type full name and method name
  2. Prefer the typeof(T)-based Call overload to get compile-time safety
  3. Supply parameters/generics arrays that match an actual overload
  4. Null-check AccessTools.Method(typeColonMethodname, parameters, generics) at patch init and fail with a clear log

Example fix

// before
CodeInstruction.Call("My.App.Logger:WriteMsg")
// after
CodeInstruction.Call("My.App.Logger:WriteMessage", new[] { typeof(string) })
Defensive patterns

Strategy: validation

Validate before calling

var mi = AccessTools.Method(typeColonMethodname, parameters, generics);
if (mi is null) throw new InvalidOperationException($"Cannot resolve {typeColonMethodname}");

Try / catch

try { il.Append(CodeInstruction.Call(typeColonMethodname, parameters)); } catch (ArgumentException ex) { log.Error($"Cannot resolve {typeColonMethodname}: {ex.Message}"); throw; }

Prevention

When it happens

Trigger: Passing a malformed or wrong typeColonMethodname (bad namespace, renamed type, missing ':Method' part), or a correctly formed string whose method does not exist or does not match the given parameters/generics.

Common situations: Hard-coded 'Namespace.Type:Method' strings that break when the target assembly is refactored; assembly-qualified names failing because Type.GetType cannot resolve the type in the current context; overload ambiguity resolved incorrectly by parameters.

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/f1355aa30debe8a7. Report an issue: GitHub.

Appendix: source

Thrown at Harmony/Public/CodeInstruction.cs:128

		/// <returns>A code instruction that calls the method matching the arguments</returns>
		///
		public static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null)
		{
			var method = AccessTools.Method(type, name, parameters, generics);
			if (method is null) throw new ArgumentException($"No method found for type={type}, name={name}, parameters={parameters.Description()}, generics={generics.Description()}");
			return new CodeInstruction(OpCodes.Call, method);
		}

		/// <summary>Creates a CodeInstruction calling a method (CALL)</summary>
		/// <param name="typeColonMethodname">The target method in the form <c>TypeFullName:MethodName</c>, where the type name matches a form recognized by <a href="https://docs.microsoft.com/en-us/dotnet/api/system.type.gettype">Type.GetType</a> like <c>Some.Namespace.Type</c>.</param>
		/// <param name="parameters">Optional parameters to target a specific overload of the method</param>
		/// <param name="generics">Optional list of types that define the generic version of the method</param>
		/// <returns>A code instruction that calls the method matching the arguments</returns>
		///
		public static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null)
		{
			var method = AccessTools.Method(typeColonMethodname, parameters, generics);
			if (method is null) throw new ArgumentException($"No method found for {typeColonMethodname}, parameters={parameters.Description()}, generics={generics.Description()}");
			return new CodeInstruction(OpCodes.Call, method);
		}

		/// <summary>Creates a CodeInstruction calling a method (CALL)</summary>
		/// <param name="expression">The lambda expression using the method</param>
		/// <returns>A new Codeinstruction</returns>
		///
		public static CodeInstruction Call(Expression<Action> expression) => new(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression));

		/// <summary>Creates a CodeInstruction calling a method (CALL)</summary>
		/// <param name="expression">The lambda expression using the method</param>
		/// <returns>A new Codeinstruction</returns>
		///
		public static CodeInstruction Call<T>(Expression<Action<T>> expression) => new(OpCodes.Call, SymbolExtensions.GetMethodInfo(expression));

		/// <summary>Creates a CodeInstruction calling a method (CALL)</summary>
		/// <param name="expression">The lambda expression using the method</param>
		/// <returns>A new Codeinstruction</returns>

View on GitHub (pinned to e7872dc170)