pardeike/Harmony · error · NotSupportedException

Unsupported generic callsite element

Error message

Unsupported generic callsite element: {etype}

What it means

InlineSignatureParser.ImportCallSite decodes a binary method-call signature blob into a Cecil CallSite. When the signature contains a generic element type (VAR or MVar — generic type/method parameters) at the callsite level, the parser cannot import it and throws NotSupportedException.

Solutions

  1. Close the generic method/type first — build the callsite signature from concrete type arguments, not generic parameters
  2. Avoid emitting inline signatures for open generic methods; emit against a constructed (closed) generic method instead
  3. Restructure the call so it goes through a non-generic delegate or wrapper method
  4. Upgrade Harmony if newer versions add generic callsite support

Example fix

// before
sig of open generic: typeof(T) parameter from generic method M<T>
// after
var closed = typeof(Consumer).GetMethod("M").MakeGenericMethod(typeof(int));
// build callsite from closed method signature
Defensive patterns

Strategy: try-catch

Try / catch

try { var callSite = parser.ImportCallSite(module); }
catch (NotSupportedException ex) when (ex.Message.StartsWith("Unsupported generic callsite element")) { /* close generics before importing */ }

Prevention

When it happens

Trigger: ImportCallSite encountering MetadataType.Var or MetadataType.MVar while decoding a callsite signature — i.e. the target method's signature is a generic parameter (e.g. calling through a generic method's own parameter type in an inline signature).

Common situations: Emitting calli instructions against signatures of open generic methods; IL of methods that pass generic type parameters via function pointers; compilers or IL generators emitting open-generic callsite signatures.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of pardeike/Harmony@e7872dc170 (2026-09-15). Data as JSON: /api/errors/d7a9a93293ea66ed. Report an issue: GitHub.

Appendix: source

Thrown at Harmony/Internal/InlineSignatureParser.cs:188

						};

					case MetadataType.RequiredModifier:
						return new InlineSignature.ModifierType()
						{
							IsOptional = false,
							Modifier = GetTypeDefOrRef(),
							Type = ReadTypeSignature()
						};

					// System.Reflection lacks SentinelType.
					/*
					case MetadataType.Sentinel:
						throw new NotSupportedException();
					*/

					case MetadataType.Var:
					case MetadataType.MVar:
						throw new NotSupportedException($"Unsupported generic callsite element: {etype}");

					case MetadataType.GenericInstance:
						_ = reader.ReadByte(); // element type, unused
						var elType = GetTypeDefOrRef();
						var arity = (int)ReadCompressedUInt32();

						return elType.MakeGenericType(
							[.. Enumerable.Range(0, arity).Select(_ => (Type)ReadTypeSignature())]
						);

					case MetadataType.Object:
						return typeof(object);

					case MetadataType.Void:
						return typeof(void);

					case MetadataType.TypedByReference:
						return typeof(TypedReference);

View on GitHub (pinned to e7872dc170)