pardeike/Harmony · error · ArgumentException

must be specified as 'Namespace.Type1.Type2:MemberName

Error message

 must be specified as 'Namespace.Type1.Type2:MemberName

What it means

Tools.TypColonName parses strings of the form 'Namespace.Type:MemberName' into a type plus member name. It throws ArgumentNullException for a null string, and ArgumentException when the string does not contain exactly one ':' (i.e. not exactly two parts after splitting). The thrown message is prefixed with the parameter name by the runtime.

Solutions

  1. Format the string exactly as 'FullTypeName:MemberName', e.g. "My.Namespace.MyType:MyMethod"
  2. Remove any extra ':' segments (e.g. drop assembly-qualified names or embedded generics/colons) before passing
  3. Ensure the string is non-null; use AccessTools.TypeByName separately when you only need the type

Example fix

// before
var tn = Tools.TypColonName("MyNamespace.MyType.MyMethod"); // missing ':'
// after
var tn = Tools.TypColonName("MyNamespace.MyType:MyMethod");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(typeColonName) || typeColonName.Split(':').Length != 2)
    throw new ArgumentException("Expected 'Namespace.Type:MemberName'");

Try / catch

TypeAndName tn;
try { tn = Tools.TypColonName(s); }
catch (ArgumentException ex) { throw new FormatException($"Bad target '{s}', expected 'Namespace.Type:MemberName'", ex); }

Prevention

When it happens

Trigger: Passing a string with zero or multiple ':' characters to an API that routes through TypColonName, e.g. "Namespace.Type.Member" (no colon) or "A:B:C" (two colons), or a null string.

Common situations: Hand-written patch attribute/target strings where the developer forgot the colon between type and member, or included an assembly-qualified suffix containing extra colons; config-driven patch targets with malformed entries.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at Harmony/Tools/Tools.cs:25

namespace HarmonyLib
{
	internal class Tools
	{
		internal static readonly bool isWindows = Environment.OSVersion.Platform.Equals(PlatformID.Win32NT);

		internal struct TypeAndName
		{
			internal Type type;
			internal string name;
		}

		internal static TypeAndName TypColonName(string typeColonName)
		{
			if (typeColonName is null)
				throw new ArgumentNullException(nameof(typeColonName));
			var parts = typeColonName.Split(':');
			if (parts.Length != 2)
				throw new ArgumentException($" must be specified as 'Namespace.Type1.Type2:MemberName", nameof(typeColonName));
			return new TypeAndName() { type = TypeByName(parts[0]), name = parts[1] };
		}

		internal static void ValidateFieldType<F>(FieldInfo fieldInfo)
		{
			var returnType = typeof(F);
			var fieldType = fieldInfo.FieldType;
			if (returnType == fieldType)
				return;
			if (fieldType.IsEnum)
			{
				var underlyingType = Enum.GetUnderlyingType(fieldType);
				if (returnType != underlyingType)
					throw new ArgumentException("FieldRefAccess return type must be the same as FieldType or " +
						$"FieldType's underlying integral type ({underlyingType}) for enum types");
			}
			else if (fieldType.IsValueType)
			{

View on GitHub (pinned to e7872dc170)