{"record":{"id":"89bf6a47a1891865","repo":"devlooped/moq","slug":"no-protected-method-0-1-found-whose-signature-is-compatible","errorCode":null,"errorMessage":"No protected method {0}.{1} found whose signature is compatible with the provided arguments ({2}).","messagePattern":"No protected method (.+?)\\.(.+?) found whose signature is compatible with the provided arguments \\((.+?)\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Moq/Protected/ProtectedMock.cs","lineNumber":400,"sourceCode":"        static void ThrowIfMethodMissing(string methodName, MethodInfo? method, object[] args)\n#endif\n        {\n            if (method == null)\n            {\n                List<string> extractedTypeNames = new List<string>();\n                foreach (object o in args)\n                {\n                    if (o is Expression expr)\n                    {\n                        extractedTypeNames.Add(expr.Type.GetFormattedName());\n                    }\n                    else\n                    {\n                        extractedTypeNames.Add(o.GetType().GetFormattedName());\n                    }\n                }\n\n                throw new ArgumentException(string.Format(\n                    CultureInfo.CurrentCulture,\n                    Resources.MethodMissing,\n                    typeof(T).Name,\n                    methodName,\n                    string.Join(\n                        \", \",\n                        extractedTypeNames.ToArray())));\n            }\n        }\n\n        static void ThrowIfPublicMethod(MethodInfo method, string reflectedTypeName)\n        {\n            if (method.IsPublic)\n            {\n                throw new ArgumentException(string.Format(\n                    CultureInfo.CurrentCulture,\n                    Resources.MethodIsPublic,\n                    reflectedTypeName,","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/devlooped/moq/blob/89a5be629c752960fe403e95ff583e4ae6f00542/src/Moq/Protected/ProtectedMock.cs#L382-L418","documentation":"ProtectedMock's string-based Setup/Verify for methods throws ArgumentException with Resources.MethodMissing when reflection cannot find a protected method with the given name whose parameters are compatible with the supplied argument values/expressions. The message lists T's name, the method name, and the formatted argument types so the signature mismatch is visible.","triggerScenarios":"mock.Protected().Setup<int>(\"Compute\", ItExpr.IsAny<long>()) where T has a Compute(int) protected method — the name exists but argument types (or argument count) do not match any protected overload.","commonSituations":"Passing wrong argument types (e.g. literal int vs long mismatch), wrong number of arguments for overloads, ref/out parameters supplied incorrectly, member renamed in a library upgrade while the call still 'succeeds' at name level.","solutions":["Match the argument expressions to the protected method's exact parameter types (use ItExpr.IsAny<T>() with the right type)","Check the protected method's signature and pick the correct overload","Ensure the method is protected/non-public instance, not public (public triggers a different guidance path)","Cast literals to the exact parameter type expected"],"exampleFix":"// before (T: protected int Compute(int x))\nmock.Protected().Setup<int>(\"Compute\", ItExpr.IsAny<long>());\n// after\nmock.Protected().Setup<int>(\"Compute\", ItExpr.IsAny<int>());","handlingStrategy":"validation","validationCode":"static bool HasProtectedMethodWithArgs(Type target, string name, params Type[] argTypes) =>\n    target.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)\n          .Any(m => m.Name == name\n                    && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(argTypes));","typeGuard":null,"tryCatchPattern":"try { mock.Protected().Setup<int>(\"Compute\", ItExpr.IsAny<int>()); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"No protected method\")) { /* fix name or argument types */ }","preventionTips":["Match ItExpr.IsAny<T>() generic types to the exact protected parameter types","Count and type-check arguments against the real protected signature","Beware int/long and other implicit-conversion mismatches — reflection needs exact types","For ref/out parameters, use the appropriate typed expression helpers"],"tags":["moq","reflection","protected-members","signature-mismatch"],"backgroundTag":"resource-not-found","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"}