{"record":{"id":"6d44a39a2190620f","repo":"pardeike/Harmony","slug":"cannot-get-method-value-without-method","errorCode":null,"errorMessage":"cannot get method value without method","messagePattern":"cannot get method value without method","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Harmony/Tools/Traverse.cs","lineNumber":143,"sourceCode":"\t\t/// <summary>Gets the current value</summary>\r\n\t\t/// <typeparam name=\"T\">The type of the value</typeparam>\r\n\t\t/// <value>The value</value>\r\n\t\t///\r\n\t\tpublic T GetValue<T>()\r\n\t\t{\r\n\t\t\tvar value = GetValue();\r\n\t\t\tif (value is null) return default;\r\n\t\t\treturn (T)value;\r\n\t\t}\r\n\r\n\t\t/// <summary>Invokes the current method with arguments and returns the result</summary>\r\n\t\t/// <param name=\"arguments\">The method arguments</param>\r\n\t\t/// <value>The value returned by the method</value>\r\n\t\t///\r\n\t\tpublic object GetValue(params object[] arguments)\r\n\t\t{\r\n\t\t\tif (_method is null)\r\n\t\t\t\tthrow new Exception(\"cannot get method value without method\");\r\n\t\t\treturn _method.Invoke(_root, arguments);\r\n\t\t}\r\n\r\n\t\t/// <summary>Invokes the current method with arguments and returns the result</summary>\r\n\t\t/// <typeparam name=\"T\">The type of the value</typeparam>\r\n\t\t/// <param name=\"arguments\">The method arguments</param>\r\n\t\t/// <value>The value returned by the method</value>\r\n\t\t///\r\n\t\tpublic T GetValue<T>(params object[] arguments)\r\n\t\t{\r\n\t\t\tif (_method is null)\r\n\t\t\t\tthrow new Exception(\"cannot get method value without method\");\r\n\t\t\treturn (T)_method.Invoke(_root, arguments);\r\n\t\t}\r\n\r\n\t\t/// <summary>Sets a value of the current field or property</summary>\r\n\t\t/// <param name=\"value\">The value</param>\r\n\t\t/// <returns>The same traverse instance</returns>\r","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Tools/Traverse.cs#L125-L161","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typo in the method name during traversal; chaining GetValue on a field traverse; API signature change in the target assembly so Method() matched nothing.","solutions":["Ensure the traversal includes .Method(\"name\", argTypes) before GetValue","Verify the method exists with Traverse.Method(...).MethodExists() or AccessTools.Method","Use Field()/Property GetValue overloads if the target is not a method"],"exampleFix":"// before\nvar result = Traverse.Create(typeof(Foo)).Method(\"Rung\").GetValue<int>(); // method name wrong\n// after\nvar tr = Traverse.Create(typeof(Foo)).Method(\"Run\");\nif (tr.MethodExists()) { var result = tr.GetValue<int>(); }","handlingStrategy":"validation","validationCode":"var tr = Traverse.Create(type).Method(\"Run\", new[] { typeof(string) });\nif (!tr.MethodExists()) throw new InvalidOperationException(\"method not found; cannot GetValue\");","typeGuard":"bool HasMethod(this Traverse tr) => tr.MethodExists();","tryCatchPattern":"try { var v = tr.GetValue(args); }\ncatch (Exception ex) when (ex.Message == \"cannot get method value without method\") { /* fix traversal path or log missing method */ }","preventionTips":["Always call MethodExists() after Method(...) before GetValue","Keep target method names/types in a constant table checked at startup against the target assembly","Don't reuse a Traverse instance across field and method operations"],"tags":["csharp","reflection","traverse"],"backgroundTag":"resource-not-found","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"}