{"record":{"id":"9b3eeacca969ae37","repo":"pardeike/Harmony","slug":"argumentvariations-contains-more-elements-than-argumenttypes","errorCode":null,"errorMessage":"argumentVariations contains more elements than argumentTypes","messagePattern":"argumentVariations contains more elements than argumentTypes","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Harmony/Public/Attributes.cs","lineNumber":400,"sourceCode":"\t\t/// <param name=\"methodType\">The <see cref=\"MethodType\"/></param>\r\n\t\t///\r\n\t\tpublic HarmonyPatch(string typeName, string methodName, MethodType methodType = MethodType.Normal)\r\n\t\t{\r\n\t\t\tinfo.declaringType = AccessTools.TypeByName(typeName);\r\n\t\t\tinfo.methodName = methodName;\r\n\t\t\tinfo.methodType = methodType;\r\n\t\t}\r\n\r\n\t\tvoid ParseSpecialArguments(Type[] argumentTypes, ArgumentType[] argumentVariations)\r\n\t\t{\r\n\t\t\tif (argumentVariations is null || argumentVariations.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tinfo.argumentTypes = argumentTypes;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tif (argumentTypes.Length < argumentVariations.Length)\r\n\t\t\t\tthrow new ArgumentException(\"argumentVariations contains more elements than argumentTypes\", nameof(argumentVariations));\r\n\r\n\t\t\tvar types = new List<Type>();\r\n\t\t\tfor (var i = 0; i < argumentTypes.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tvar type = argumentTypes[i];\r\n\t\t\t\tswitch (argumentVariations[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase ArgumentType.Normal:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase ArgumentType.Ref:\r\n\t\t\t\t\tcase ArgumentType.Out:\r\n\t\t\t\t\t\ttype = type.MakeByRefType();\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase ArgumentType.Pointer:\r\n\t\t\t\t\t\ttype = type.MakePointerType();\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\ttypes.Add(type);\r","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Public/Attributes.cs#L382-L418","documentation":"HarmonyPatch attributes accept argumentVariations (ArgumentType markers like Ref/Out/Normal) that must align positionally with argumentTypes. Harmony throws ArgumentException when there are more variation entries than parameter types, since each variation needs a matching type.","triggerScenarios":"[HarmonyPatch(..., argumentTypes: new[]{typeof(int)}, argumentVariations: new[]{ArgumentType.Normal, ArgumentType.Ref})] — the variations array is longer than the types array. Also happens when argumentTypes is left to be inferred but variations are supplied explicitly.","commonSituations":"Adding a Ref/Out marker for a parameter you added to the patch signature but forgot to add to argumentTypes; copy-pasting attribute templates where the two arrays drifted out of sync.","solutions":["Make argumentVariations.Length <= argumentTypes.Length, pairing each variation with its type","If a parameter has no special variation, omit its entry instead of adding a placeholder that extends the array","If argumentTypes is empty/omitted, pass the full type list when using variations"],"exampleFix":"// before\n[HarmonyPatch(typeof(Foo), nameof(Foo.Bar), argumentTypes: new[] { typeof(int) }, argumentVariations: new[] { ArgumentType.Normal, ArgumentType.Ref })]\n// after\n[HarmonyPatch(typeof(Foo), nameof(Foo.Bar), argumentTypes: new[] { typeof(int), typeof(string) }, argumentVariations: new[] { ArgumentType.Normal, ArgumentType.Ref })]","handlingStrategy":"validation","validationCode":"if (argumentVariations is { Length: > 0 } && (argumentTypes is null || argumentVariations.Length > argumentTypes.Length))\n    throw new InvalidOperationException(\"argumentVariations must not exceed argumentTypes\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep argumentTypes and argumentVariations arrays positionally aligned","Omit variations entries for plain parameters instead of padding","Review attribute arguments whenever patch method signatures change"],"tags":["attributes","patching","arguments","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"}