{"record":{"id":"99acb8e4f6839287","repo":"pardeike/Harmony","slug":"nameof-positions-cannot-contain-zeros","errorCode":null,"errorMessage":"{nameof(positions)} cannot contain zeros","messagePattern":"(.+?) cannot contain zeros","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Harmony/Public/InnerMethod.cs","lineNumber":37,"sourceCode":"\t\t[NonSerialized]\r\n\t\tprivate MethodInfo method;\r\n\t\tprivate int methodToken;\r\n\t\tprivate string moduleGUID;\r\n\r\n\t\t/// <summary>Which occcurances (1-based) of the method, negative numbers are counting from the end, empty array means all occurances</summary>\r\n\t\t///\r\n\t\tpublic int[] positions;\r\n\r\n\t\t/// <summary>Creates an InnerMethod</summary>\r\n\t\t/// <param name=\"method\">The inner method</param>\r\n\t\t/// <param name=\"positions\">Which occcurances (1-based) of the method, negative numbers are counting from the end, empty array means all occurances</param>\r\n\t\t///\r\n\t\tpublic InnerMethod(MethodInfo method, params int[] positions)\r\n\t\t{\r\n\t\t\tif (method == null)\r\n\t\t\t\tthrow new ArgumentNullException(nameof(method));\r\n\t\t\tif (positions.Any(p => p == 0))\r\n\t\t\t\tthrow new ArgumentException($\"{nameof(positions)} cannot contain zeros\");\r\n\r\n\t\t\tMethod = method;\r\n\t\t\tthis.positions = positions;\r\n\t\t}\r\n\r\n\t\tinternal InnerMethod(int methodToken, string moduleGUID, int[] positions)\r\n\t\t{\r\n\t\t\tthis.methodToken = methodToken;\r\n\t\t\tthis.moduleGUID = moduleGUID;\r\n\t\t\tthis.positions = positions;\r\n\t\t}\r\n\r\n\t\t/// <summary>The inner method</summary>\r\n\t\t///\r\n#if NET5_0_OR_GREATER\r\n\t\t[JsonIgnore]\r\n#endif\r\n\t\tpublic MethodInfo Method\r","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Public/InnerMethod.cs#L19-L55","documentation":"InnerMethod wraps a MethodInfo together with parameter positions that should be treated specially (e.g. skipped or rewritten). Harmony rejects a positions array containing 0 because positions are 1-based argument indexes; 0 is meaningless and would corrupt argument handling downstream.","triggerScenarios":"Calling the InnerMethod(MethodInfo, params int[]) constructor with any element of the positions array equal to 0, typically from computed/loop-derived indexes with an off-by-one.","commonSituations":"Transpilers or patch tools building argument-redirect helpers that start counting at 0 instead of 1; arrays built from zero-initialized buffers; passing raw loop counters.","solutions":["Use 1-based argument positions (first argument is 1, instance 'this' context is handled separately)","Filter out zeros before constructing: positions = positions.Where(p => p != 0).ToArray()","Double-check the loop or mapping that generates the indexes for an off-by-one"],"exampleFix":"// before\nnew InnerMethod(method, 0, 2);\n// after\nnew InnerMethod(method, 1, 2);","handlingStrategy":"validation","validationCode":"if (positions.Contains(0)) throw new ArgumentException(\"positions must be 1-based and non-zero\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat argument positions as 1-based everywhere in Harmony","Sanitize index arrays derived from loops before passing them to Harmony APIs"],"tags":["argument","off-by-one","harmony","csharp"],"backgroundTag":"invalid-argument-value","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"}