dotnet/wpf · error · ArgumentException
The parameter must implement interface
Error message
The parameter must implement interface {interfaceType}. What it means
Verify.ImplementsInterface walks the parameter's type hierarchy (including interfaces of base types) and throws ArgumentException with the message "The parameter must implement interface {interfaceType}." if no match is found. Unlike TypeSupportsInterface it takes the object itself and works via interface list traversal.
Solutions
- Make the parameter's class implement interfaceType (directly or via a base class).
- Pass a different instance that already implements the required interface.
- Fix the DI registration/type hierarchy so the instance actually satisfies the interface.
Example fix
// before
ctx.SetValue(new MyProvider()); // MyProvider lacks IServiceProvider
// after
class MyProvider : IServiceProvider { ... }
ctx.SetValue(new MyProvider()); Defensive patterns
Strategy: type-guard
Validate before calling
if (parameter is TRequired) { api.Call(parameter); } else { /* wrap or reject */ } Type guard
static bool ImplementsInterfaceOf<TReq>(object o) => o is TReq;
Try / catch
try { api.Call(obj); }
catch (ArgumentException ex) when (ex.Message.Contains("must implement interface")) { /* supply an implementing instance */ } Prevention
- Program against interfaces and have concrete classes explicitly implement them.
- Check DI container registrations bind the interface, not just the concrete type.
- Validate object graphs at construction time with `is` checks.
When it happens
Trigger: Passing an object instance that (or whose base types) do not implement interfaceType into a WPF API that calls Verify.ImplementsInterface.
Common situations: Passing mocks, subclasses, or wrappers that dropped an interface; dependency-injection bindings registered against the concrete type instead of the interface; codegen or proxy objects that omit the interface.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- The type of this parameter does not support a required…
- SR.IncorrectLocatorPartType
- SR.Invalid_IInputElement
- SR.ITypeDataObject_Not_Implemented
- SR.Mismatched_RoutedEvent
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0d8e047600cf5236.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs:290
internal static void ImplementsInterface(object parameter, Type interfaceType, string parameterName)
{
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)
{
throw new ArgumentException($"The parameter must implement interface {interfaceType}.", parameterName);
}
}
}
}
View on GitHub (pinned to 81131a70a4)