pardeike/Harmony · error · Exception

cannot get method value without method

Error message

cannot get method value without method

What it means

Traverse.GetValue(arguments) invokes the method currently selected by the traversal, but the traverse holds no method (_method is null) — the traversal path ended at a field, property, or dead end. Harmony throws a plain Exception instead of silently returning null.

Solutions

  1. Ensure the traversal includes .Method("name", argTypes) before GetValue
  2. Verify the method exists with Traverse.Method(...).MethodExists() or AccessTools.Method
  3. Use Field()/Property GetValue overloads if the target is not a method

Example fix

// before
var result = Traverse.Create(typeof(Foo)).Method("Rung").GetValue<int>(); // method name wrong
// after
var tr = Traverse.Create(typeof(Foo)).Method("Run");
if (tr.MethodExists()) { var result = tr.GetValue<int>(); }
Defensive patterns

Strategy: validation

Validate before calling

var tr = Traverse.Create(type).Method("Run", new[] { typeof(string) });
if (!tr.MethodExists()) throw new InvalidOperationException("method not found; cannot GetValue");

Type guard

bool HasMethod(this Traverse tr) => tr.MethodExists();

Try / catch

try { var v = tr.GetValue(args); }
catch (Exception ex) when (ex.Message == "cannot get method value without method") { /* fix traversal path or log missing method */ }

Prevention

When it happens

Trigger: Calling traverse.GetValue(args) after a path like Traverse.Create(type).Field(x) (no .Method(...)) or after Method(name) failed to resolve the method, leaving _method null.

Common situations: Typo in the method name during traversal; chaining GetValue on a field traverse; API signature change in the target assembly so Method() matched nothing.

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

Appendix: source

Thrown at Harmony/Tools/Traverse.cs:143

		/// <summary>Gets the current value</summary>
		/// <typeparam name="T">The type of the value</typeparam>
		/// <value>The value</value>
		///
		public T GetValue<T>()
		{
			var value = GetValue();
			if (value is null) return default;
			return (T)value;
		}

		/// <summary>Invokes the current method with arguments and returns the result</summary>
		/// <param name="arguments">The method arguments</param>
		/// <value>The value returned by the method</value>
		///
		public object GetValue(params object[] arguments)
		{
			if (_method is null)
				throw new Exception("cannot get method value without method");
			return _method.Invoke(_root, arguments);
		}

		/// <summary>Invokes the current method with arguments and returns the result</summary>
		/// <typeparam name="T">The type of the value</typeparam>
		/// <param name="arguments">The method arguments</param>
		/// <value>The value returned by the method</value>
		///
		public T GetValue<T>(params object[] arguments)
		{
			if (_method is null)
				throw new Exception("cannot get method value without method");
			return (T)_method.Invoke(_root, arguments);
		}

		/// <summary>Sets a value of the current field or property</summary>
		/// <param name="value">The value</param>
		/// <returns>The same traverse instance</returns>

View on GitHub (pinned to e7872dc170)