dotnet/maui · error · ArgumentException
The type of this parameter does not support a required inter
Error message
The type of this parameter does not support a required interface
What it means
Verify.TypeSupportsInterface throws ArgumentException when type.GetInterface(interfaceType.Name) returns null — i.e. the given Type does not implement the required interface. It is used to validate that a dynamically-provided Type (from reflection, plugin loading, or DI) satisfies a contract before instantiation.
Source
Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs:285
if (value < lowerBoundInclusive || value > upperBoundInclusive)
{
Assert.Fail();
throw new ArgumentException(message, parameter);
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void TypeSupportsInterface(Type type, Type interfaceType, string parameterName)
{
Assert.IsNeitherNullNorEmpty(parameterName);
Verify.IsNotNull(type, "type");
Verify.IsNotNull(interfaceType, "interfaceType");
if (type.GetInterface(interfaceType.Name) == null)
{
Assert.Fail();
throw new ArgumentException("The type of this parameter does not support a required interface", parameterName);
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void FileExists(string filePath, string parameterName)
{
Verify.IsNeitherNullNorEmpty(filePath, parameterName);
if (!File.Exists(filePath))
{
Assert.Fail();
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "No file exists at \"{0}\"", filePath), parameterName);
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
internal static void ImplementsInterface(object parameter, Type interfaceType, string parameterName)View on GitHub (pinned to f377ff1c5e)
Solutions
- Check type.GetInterface(interfaceType.Name) != null (or typeof(IFoo).IsAssignableFrom(type)) before calling.
- Verify the loaded assembly matches the expected interface version.
- Use IsAssignableFrom for a more reliable check than GetInterface by name.
Example fix
// before
factory.Create(pluginType); // pluginType may not implement IPlugin
// after
if (!typeof(IPlugin).IsAssignableFrom(pluginType))
{
throw new ArgumentException($"{pluginType} does not implement IPlugin.", nameof(pluginType));
}
factory.Create(pluginType); Defensive patterns
Strategy: validation
Validate before calling
// Pre-check: type must implement the required interface
if (!interfaceType.IsAssignableFrom(type))
{
throw new ArgumentException($"{type} does not implement {interfaceType}.", nameof(type));
}
SomeApi(type); Prevention
- Use IsAssignableFrom for reliable interface checks rather than GetInterface by name.
- Verify loaded assemblies match the expected interface version in plugin scenarios.
- Validate plugin types at load time before registration.
When it happens
Trigger: Calling a method guarded by Verify.TypeSupportsInterface(type, typeof(IFoo), paramName) with a Type that does not implement IFoo. The reflection lookup fails and the guard fires.
Common situations: Plugin systems loading a Type by name that does not implement the expected contract; DI container registration with the wrong interface; a derived type that dropped an interface its base had; assembly version mismatch where the interface was renamed.
Related errors
- The parameter must implement interface {0}.
- The parameter cannot be either null or empty.
- The parameter cannot be either null or empty or consist only
- The parameter must not be the default value.
- The parameter must be null.
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/d74a31bccad6ad57.
Report an issue: GitHub.