{"record":{"id":"695922ea19662441","repo":"devlooped/moq","slug":"public-0-bool-1-2-in-class-3","errorCode":null,"errorMessage":"\"public {0}bool {1}({2}) in class {3}.\"","messagePattern":"\"public (.+?)bool (.+?)\\((.+?)\\) in class (.+?)\\.\"","errorType":"exception","errorClass":"MissingMethodException","httpStatus":null,"severity":"error","filePath":"src/Moq/Matchers/MatcherAttributeMatcher.cs","lineNumber":72,"sourceCode":"                method = call.Method.DeclaringType!.GetMethods(call.Method.Name)\n                    .Where(m =>\n                        m.IsGenericMethodDefinition &&\n                        m.GetGenericArguments().Length ==\n                            call.Method.GetGenericMethodDefinition().GetGenericArguments().Length &&\n                        expectedParametersTypes.SequenceEqual(\n                            m.MakeGenericMethod(genericArgs).GetParameters().Select(p => p.ParameterType)))\n                    .Select(m => m.MakeGenericMethod(genericArgs))\n                    .FirstOrDefault();\n            }\n            else\n            {\n                method = call.Method.DeclaringType!.GetMethod(call.Method.Name, expectedParametersTypes);\n            }\n\n            // throw if validatorMethod doesn't exists\t\t\t\n            if (method == null)\n            {\n                throw new MissingMethodException(string.Format(CultureInfo.CurrentCulture,\n                    \"public {0}bool {1}({2}) in class {3}.\",\n                    call.Method.IsStatic ? \"static \" : String.Empty,\n                    call.Method.Name,\n                    String.Join(\", \", expectedParametersTypes.Select(x => x.Name).ToArray()),\n                    call.Method.DeclaringType!.ToString()));\n            }\n            return method;\n        }\n\n        public bool Matches(object? argument, Type parameterType)\n        {\n            // use matcher Expression to get extra arguments\n            var extraArgs = this.expression.Arguments.Select(ae => ((ConstantExpression)ae.PartialEval()).Value);\n            var args = new[] { argument }.Concat(extraArgs).ToArray();\n            // for static and non-static method\n            var instance = this.expression.Object == null ? null : ((ConstantExpression)this.expression.Object.PartialEval()).Value;\n            return (bool)validatorMethod.Invoke(instance, args)!;\n        }","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/devlooped/moq/blob/89a5be629c752960fe403e95ff583e4ae6f00542/src/Moq/Matchers/MatcherAttributeMatcher.cs#L54-L90","documentation":"MatcherAttributeMatcher throws MissingMethodException when a [Matcher] attribute-marked method cannot be resolved: the validator method with the expected signature (public, matching parameter types, same return bool) does not exist on the declaring type. The error message spells out the exact required signature.","triggerScenarios":"Using a custom [Matcher] class whose TryMatch/validate method is not public, is static without matching expectation, has wrong parameter types, or was renamed — typically surfaced when the matcher is used in a setup expression.","commonSituations":"Custom matcher classes copied from samples with private/protected validator methods; renamed methods after refactoring; parameter type lists out of sync with the matched method.","solutions":["Make the validator method public, with signature `public bool MethodName(params...)` matching the expected parameter types shown in the message","Match static-ness: add `static` if the message shows the call is static","Ensure parameter types in the matcher method exactly match those of the mocked method call"],"exampleFix":"// before\nprivate bool InRange(int value) => value >= 1 && value <= 10;\n// after\npublic bool InRange(int value) => value >= 1 && value <= 10;","handlingStrategy":"validation","validationCode":"var m = typeof(MyMatcher).GetMethod(\"InRange\", new[] { typeof(int) });\nif (m == null || !m.IsPublic || m.ReturnType != typeof(bool)) throw new InvalidOperationException(\"Matcher validator must be public bool with matching params\");","typeGuard":"static bool IsValidMatcherMethod(MethodInfo? mi) => mi is { IsPublic: true } && mi.ReturnType == typeof(bool);","tryCatchPattern":"try { mock.Setup(m => m.Do(InRange(5))); } catch (MissingMethodException ex) when (ex.Message.Contains(\"bool\")) { /* make validator public with exact signature */ }","preventionTips":["Keep [Matcher] validator methods public and bool-returning","Keep validator parameter types identical to the matched method's","Write a reflection-based unit test for custom matcher classes"],"tags":["moq","matcher-attribute","missing-method","reflection"],"backgroundTag":"method-not-implemented","analyzedSha":"89a5be629c752960fe403e95ff583e4ae6f00542","analyzedAt":"2026-09-16T05:31:39.496Z","contentChangedAt":"2026-09-16T05:31:39.496Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}