{"record":{"id":"d74a31bccad6ad57","repo":"dotnet/maui","slug":"the-type-of-this-parameter-does-not-support-a-requ","errorCode":null,"errorMessage":"The type of this parameter does not support a required interface","messagePattern":"The type of this parameter does not support a required interface","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":285,"sourceCode":"\t\t\tif (value < lowerBoundInclusive || value > upperBoundInclusive)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(message, parameter);\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void TypeSupportsInterface(Type type, Type interfaceType, string parameterName)\n\t\t{\n\t\t\tAssert.IsNeitherNullNorEmpty(parameterName);\n\t\t\tVerify.IsNotNull(type, \"type\");\n\t\t\tVerify.IsNotNull(interfaceType, \"interfaceType\");\n\n\t\t\tif (type.GetInterface(interfaceType.Name) == null)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(\"The type of this parameter does not support a required interface\", parameterName);\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void FileExists(string filePath, string parameterName)\n\t\t{\n\t\t\tVerify.IsNeitherNullNorEmpty(filePath, parameterName);\n\t\t\tif (!File.Exists(filePath))\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(string.Format(CultureInfo.InvariantCulture, \"No file exists at \\\"{0}\\\"\", filePath), parameterName);\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tinternal static void ImplementsInterface(object parameter, Type interfaceType, string parameterName)","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs#L267-L303","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfactory.Create(pluginType); // pluginType may not implement IPlugin\n\n// after\nif (!typeof(IPlugin).IsAssignableFrom(pluginType))\n{\n    throw new ArgumentException($\"{pluginType} does not implement IPlugin.\", nameof(pluginType));\n}\nfactory.Create(pluginType);","handlingStrategy":"validation","validationCode":"// Pre-check: type must implement the required interface\nif (!interfaceType.IsAssignableFrom(type))\n{\n    throw new ArgumentException($\"{type} does not implement {interfaceType}.\", nameof(type));\n}\nSomeApi(type);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["validation","reflection","interface","type","verify"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}