{"record":{"id":"0d8e047600cf5236","repo":"dotnet/wpf","slug":"the-parameter-must-implement-interface-interfacetype","errorCode":null,"errorMessage":"The parameter must implement interface {interfaceType}.","messagePattern":"The parameter must implement interface (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":290,"sourceCode":"        internal static void ImplementsInterface(object parameter, Type interfaceType, string parameterName)\n        {\n            Assert.IsNotNull(parameter);\n            Assert.IsNotNull(interfaceType);\n            Assert.IsTrue(interfaceType.IsInterface);\n\n            bool isImplemented = false;\n            foreach (var ifaceType in parameter.GetType().GetInterfaces())\n            {\n                if (ifaceType == interfaceType)\n                {\n                    isImplemented = true;\n                    break;\n                }\n            }\n\n            if (!isImplemented)\n            {\n                throw new ArgumentException($\"The parameter must implement interface {interfaceType}.\", parameterName);\n            }\n        }\n    }\n}\n","sourceCodeStart":272,"sourceCodeEnd":295,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L272-L295","documentation":"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.","triggerScenarios":"Passing an object instance that (or whose base types) do not implement interfaceType into a WPF API that calls Verify.ImplementsInterface.","commonSituations":"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.","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."],"exampleFix":"// before\nctx.SetValue(new MyProvider()); // MyProvider lacks IServiceProvider\n// after\nclass MyProvider : IServiceProvider { ... }\nctx.SetValue(new MyProvider());","handlingStrategy":"type-guard","validationCode":"if (parameter is TRequired) { api.Call(parameter); } else { /* wrap or reject */ }","typeGuard":"static bool ImplementsInterfaceOf<TReq>(object o) => o is TReq;","tryCatchPattern":"try { api.Call(obj); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"must implement interface\")) { /* supply an implementing instance */ }","preventionTips":["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."],"tags":["type-mismatch","interface","wpf","argument-validation"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}