pardeike/Harmony · error · ArgumentException

First argument corrupt

Error message

First argument corrupt

What it means

ReturningStructs_I08.IM08 is a test asset method that guards its contract: the first string argument must equal "test". The ArgumentException fires when the patcher/prefix passes a corrupted or missing first argument, which is how Harmony's struct-returning method tests detect broken argument marshalling.

Solutions

  1. Pass exactly "test" as the first argument to IM08
  2. Fix the patch signature so the first argument is forwarded unmodified (correct [HarmonyArgument]/parameter order)
  3. Remove or fix the patch that rewrites the argument list

Example fix

// before
var inst = new ReturningStructs_I08(); inst.IM08("wrong");
// after
var inst = new ReturningStructs_I08(); inst.IM08("test");
Defensive patterns

Strategy: try-catch

Validate before calling

Debug.Assert(s == "test");

Type guard

null

Try / catch

try { inst.IM08(s); } catch (ArgumentException ex) when (ex.Message == "First argument corrupt") { /* handle */ }

Prevention

When it happens

Trigger: Invoking IM08 (directly or through a Harmony patch that alters the argument list) with s != "test" — e.g. a transpile/prefix that drops or reorders arguments, or calling IM08 with a different string.

Common situations: Writing a Harmony prefix/postfix with the wrong parameter order for struct-returning methods; passing null/empty strings in test harnesses; signature changes in target methods.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at HarmonyTests/Patching/Assets/ReturningStructMethods.cs:83

			if (s != "test") throw new ArgumentException("First argument corrupt");
			return new St06();
		}
	}

	public class ReturningStructs_I07
	{
		public St07 IM07(string s)
		{
			if (s != "test") throw new ArgumentException("First argument corrupt");
			return new St07();
		}
	}

	public class ReturningStructs_I08
	{
		public St08 IM08(string s)
		{
			if (s != "test") throw new ArgumentException("First argument corrupt");
			return new St08();
		}
	}

	public class ReturningStructs_I09
	{
		public St09 IM09(string s)
		{
			if (s != "test") throw new ArgumentException("First argument corrupt");
			return new St09();
		}
	}

	public class ReturningStructs_I10
	{
		public St10 IM10(string s)
		{
			if (s != "test") throw new ArgumentException("First argument corrupt");

View on GitHub (pinned to e7872dc170)