{"record":{"id":"1451b2b257cfdc64","repo":"dotnet/maui","slug":"the-parameter-must-implement-interface-0","errorCode":null,"errorMessage":"The parameter must implement interface {0}.","messagePattern":"The parameter must implement interface (.+?)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":322,"sourceCode":"\t\t{\n\t\t\tAssert.IsNotNull(parameter);\n\t\t\tAssert.IsNotNull(interfaceType);\n\t\t\tAssert.IsTrue(interfaceType.IsInterface);\n\n\t\t\tbool isImplemented = false;\n\t\t\tforeach (var ifaceType in parameter.GetType().GetInterfaces())\n\t\t\t{\n\t\t\t\tif (ifaceType == interfaceType)\n\t\t\t\t{\n\t\t\t\t\tisImplemented = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!isImplemented)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(string.Format(CultureInfo.InvariantCulture, \"The parameter must implement interface {0}.\", interfaceType.ToString()), parameterName);\n\t\t\t}\n\t\t}\n\t}\n}\n","sourceCodeStart":304,"sourceCodeEnd":327,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs#L304-L327","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check typeof(IBar).IsAssignableFrom(obj.GetType()) before the call.","Ensure the object's type declares the required interface (not just structurally matching members).","If testing with mocks, configure the mock to implement the interface."],"exampleFix":"// before\nprocessor.Run(dataObject); // may not implement IProcessable\n\n// after\nif (!(dataObject is IProcessable))\n{\n    throw new ArgumentException($\"{dataObject.GetType()} does not implement IProcessable.\", nameof(dataObject));\n}\nprocessor.Run(dataObject);","handlingStrategy":"validation","validationCode":"// Pre-check: instance must implement the required interface\nif (!interfaceType.IsInstanceOfType(parameter))\n{\n    throw new ArgumentException($\"{parameter.GetType()} does not implement {interfaceType}.\", nameof(parameter));\n}\nSomeApi(parameter);","typeGuard":"// Type guard / pattern check for DependencyObject or interface\nstatic bool ImplementsInterface<TInterface>(object obj) where TInterface : class\n{\n    return obj is TInterface;\n}","tryCatchPattern":null,"preventionTips":["Use the 'is' pattern (obj is IBar) to check interface implementation before forwarding.","Ensure mocks and stubs implement the required interface in test code.","Watch for explicit interface implementations that may not appear in simple casts."],"tags":["validation","reflection","interface","argument","verify"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}