dotnet/maui · error · ArgumentException

The parameter must implement interface {0}.

Error message

The parameter must implement interface {0}.

What it means

Verify.ImplementsInterface (internal) throws ArgumentException when an object's runtime type does not implement the required interface. Unlike TypeSupportsInterface (which checks a Type), this checks a live instance by iterating parameter.GetType().GetInterfaces(). The message formats the interface type name.

Source

Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs:322

		{
			Assert.IsNotNull(parameter);
			Assert.IsNotNull(interfaceType);
			Assert.IsTrue(interfaceType.IsInterface);

			bool isImplemented = false;
			foreach (var ifaceType in parameter.GetType().GetInterfaces())
			{
				if (ifaceType == interfaceType)
				{
					isImplemented = true;
					break;
				}
			}

			if (!isImplemented)
			{
				Assert.Fail();
				throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The parameter must implement interface {0}.", interfaceType.ToString()), parameterName);
			}
		}
	}
}

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Check typeof(IBar).IsAssignableFrom(obj.GetType()) before the call.
  2. Ensure the object's type declares the required interface (not just structurally matching members).
  3. If testing with mocks, configure the mock to implement the interface.

Example fix

// before
processor.Run(dataObject); // may not implement IProcessable

// after
if (!(dataObject is IProcessable))
{
    throw new ArgumentException($"{dataObject.GetType()} does not implement IProcessable.", nameof(dataObject));
}
processor.Run(dataObject);
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check: instance must implement the required interface
if (!interfaceType.IsInstanceOfType(parameter))
{
    throw new ArgumentException($"{parameter.GetType()} does not implement {interfaceType}.", nameof(parameter));
}
SomeApi(parameter);

Type guard

// Type guard / pattern check for DependencyObject or interface
static bool ImplementsInterface<TInterface>(object obj) where TInterface : class
{
    return obj is TInterface;
}

Prevention

When it happens

Trigger: Calling an internal method guarded by Verify.ImplementsInterface(obj, typeof(IBar), paramName) where obj's runtime type does not implement IBar. The interface iteration finds no match and the guard fires.

Common situations: Passing a wrapper or proxy object that does not forward the interface; version mismatch where the interface was added in a newer build; a mock or stub missing the interface in tests; a derived class that did not re-implement an explicitly-implemented interface.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/1451b2b257cfdc64. Report an issue: GitHub.