{"record":{"id":"0a825b15997e2b6a","repo":"pardeike/Harmony","slug":"wrong-null-argument-codeinstruction","errorCode":null,"errorMessage":"Wrong null argument: {codeInstruction}","messagePattern":"Wrong null argument: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Harmony/Internal/MethodCreatorTools.cs","lineNumber":634,"sourceCode":"\t\t\t\t// mark all labels\r\n\t\t\t\tcodeInstruction.labels.Do(label => emitter.MarkLabel(label));\r\n\r\n\t\t\t\t// start all exception blocks\r\n\t\t\t\tcodeInstruction.blocks.Do(block => emitter.MarkBlockBefore(block, out var _));\r\n\r\n\t\t\t\tvar code = codeInstruction.opcode;\r\n\t\t\t\tvar operand = codeInstruction.operand;\r\n\r\n\t\t\t\tswitch (code.OperandType)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase OperandType.InlineNone:\r\n\t\t\t\t\t\tif (codeInstruction.IsAnnotation() == null)\r\n\t\t\t\t\t\t\temitter.Emit(code);\r\n\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\tcase OperandType.InlineSig:\r\n\t\t\t\t\t\tif (operand is null)\r\n\t\t\t\t\t\t\tthrow new Exception($\"Wrong null argument: {codeInstruction}\");\r\n\t\t\t\t\t\tif ((operand is ICallSiteGenerator) is false)\r\n\t\t\t\t\t\t\tthrow new Exception($\"Wrong Emit argument type {operand.GetType()} in {codeInstruction}\");\r\n\t\t\t\t\t\temitter.Emit(code, (ICallSiteGenerator)operand);\r\n\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tif (operand is null)\r\n\t\t\t\t\t\t\tthrow new Exception($\"Wrong null argument: {codeInstruction}\");\r\n\t\t\t\t\t\temitter.DynEmit(code, operand);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tcodeInstruction.blocks.Do(block => emitter.MarkBlockAfter(block));\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tstatic List<CodeInstruction> InitializeOutParameter(int argIndex, Type type)\r\n\t\t{\r","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/pardeike/Harmony/blob/e7872dc17008bc0ca2b3de1f53fd4120dbd7a17c/Harmony/Internal/MethodCreatorTools.cs#L616-L652","documentation":"During EmitCodes, an instruction with an InlineSig operand type (a calli signature) arrived with a null operand. Harmony's emitter cannot pass a null call-site signature to the underlying emitter, so this indicates malformed/corrupted IL in the transpiled instruction list.","triggerScenarios":"A transpiler emits an Instruction whose opcode is calli (InlineSig) but sets operand to null, or an IL manipulation step stripped the signature operand before EmitCodes runs.","commonSituations":"Custom transpilers that copy instructions but forget the operand, IL manipulation libraries (e.g. manual Cecil-style edits) producing calli without a signature, or hand-built CodeInstruction lists.","solutions":["Find the transpiler producing the calli instruction and set its operand to a valid signature (ILGenerator-compatible SignatureHelper/ICallSiteGenerator).","Remove or replace the null-operand calli instruction in the transpiled list.","Dump the transpiled instructions (Harmony.DEBUG logging) to locate the offending instruction."],"exampleFix":"// before\nyield return new CodeInstruction(OpCodes.Calli, null);\n\n// after\nyield return new CodeInstruction(OpCodes.Calli, signatureHelper); // valid ICallSiteGenerator operand","handlingStrategy":"type-guard","validationCode":"foreach (var ci in transpiledInstructions)\n    if (ci.opcode.OperandType == OperandType.InlineSig && ci.operand is null)\n        throw new InvalidOperationException(\"calli instruction without signature\");","typeGuard":"static bool HasValidSigOperand(CodeInstruction ci) =>\n    ci.opcode.OperandType != OperandType.InlineSig || ci.operand is ICallSiteGenerator;","tryCatchPattern":"try { harmony.Patch(original, transpiler: t); }\ncatch (Exception ex) when (ex.Message.StartsWith(\"Wrong null argument\"))\n{ Logger.Error($\"Transpiler emitted calli with null operand: {ex.Message}\"); }","preventionTips":["Never construct calli instructions by hand; copy both opcode and operand when cloning.","Test transpilers with Harmony.DEBUG to dump emitted IL before shipping.","Avoid manipulating raw calli sites unless you fully rebuild the signature."],"tags":["harmony","transpiler","il-emission"],"backgroundTag":"null-argument","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"}