{"record":{"id":"6ebd9e2a18954c35","repo":"LuckyPennySoftware/AutoMapper","slug":"type-conditiontype-name-does-not-implement-ico","errorCode":null,"errorMessage":"Type '{conditionType.Name}' does not implement ICondition<TSource, TDestination, TMember>","messagePattern":"Type '(.+?)' does not implement ICondition<TSource, TDestination, TMember>","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/AutoMapper/Configuration/MemberConfigurationExpression.cs","lineNumber":85,"sourceCode":"        _sourceMembers = ReflectionHelper.GetMemberPath(_sourceType, sourceMembersPath);\n        PropertyMapActions.Add(pm => pm.MapFrom(sourceMembersPath, _sourceMembers));\n    }\n    public void Condition<TCondition>() where TCondition : ICondition<TSource, TDestination, TMember>\n    {\n        var expr = CreateConditionExpression(typeof(TCondition));\n        ConditionCore(expr);\n    }\n    protected virtual Expression<Func<TSource, TDestination, TMember, TMember, ResolutionContext, bool>> CreateConditionExpression(Type conditionType)\n    {\n        var srcParam = Parameter(typeof(TSource));\n        var destParam = Parameter(typeof(TDestination));\n        var srcMemberParam = Parameter(typeof(TMember));\n        var destMemberParam = Parameter(typeof(TMember));\n        var ctxParam = Parameter(typeof(ResolutionContext));\n\n        var conditionInstance = ServiceLocator(conditionType);\n        var interfaceType = conditionType.GetGenericInterface(typeof(ICondition<,,>)) ??\n            throw new InvalidOperationException($\"Type '{conditionType.Name}' does not implement ICondition<TSource, TDestination, TMember>\");\n        var evaluateMethod = interfaceType.GetMethod(\"Evaluate\");\n\n        // Get the actual types from the interface\n        var interfaceArgs = interfaceType.GenericTypeArguments;\n        var expectedSourceType = interfaceArgs[0];\n        var expectedDestType = interfaceArgs[1];\n        var expectedMemberType = interfaceArgs[2];\n\n        // Cast parameters to the expected types if needed\n        var srcArg = typeof(TSource) == expectedSourceType ? srcParam : (Expression)Convert(srcParam, expectedSourceType);\n        var destArg = typeof(TDestination) == expectedDestType ? destParam : (Expression)Convert(destParam, expectedDestType);\n        var srcMemberArg = typeof(TMember) == expectedMemberType ? srcMemberParam : (Expression)Convert(srcMemberParam, expectedMemberType);\n        var destMemberArg = typeof(TMember) == expectedMemberType ? destMemberParam : (Expression)Convert(destMemberParam, expectedMemberType);\n\n        var callExpression = Call(\n            Convert(conditionInstance, interfaceType),\n            evaluateMethod,\n            srcArg, destArg, srcMemberArg, destMemberArg, ctxParam","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/LuckyPennySoftware/AutoMapper/blob/dfa6dd587c5854b4beee5934beb39ba6e9569b84/src/AutoMapper/Configuration/MemberConfigurationExpression.cs#L67-L103","documentation":"Thrown by Condition<TCondition>() when the generic type argument does not implement the ICondition<TSource, TDestination, TMember> interface. The CreateConditionExpression method calls GetGenericInterface(typeof(ICondition<,,>)) and throws InvalidOperationException if the result is null, meaning no closed generic ICondition interface was found on the type.","triggerScenarios":"Calling .Condition<MyCondition>() inside a ForMember callback where MyCondition implements IValueResolver or some other interface instead of ICondition<TSource, TDestination, TMember>. Also happens when MyCondition implements ICondition with different generic type arguments than the map's TSource/TDestination/TMember.","commonSituations":"Implementing the wrong interface by mistake; using a value resolver class where a condition class was expected; type argument mismatch between the condition's generic arguments and the mapping's types.","solutions":["Implement ICondition<TSource, TDestination, TMember> on your condition class with the exact same generic type arguments as the mapping.","Alternatively, use one of the lambda Condition(...) overloads instead of a class-based condition.","Double-check that the condition class's generic arguments match the source, destination, and member types of the ForMember call."],"exampleFix":"// before — wrong interface\npublic class MyCondition : IValueResolver<Source, Dest, bool> { /* ... */ }\nCreateMap<Source, Dest>().ForMember(d => d.IsActive, opt => opt.Condition<MyCondition>());\n\n// after — correct interface with matching generic arguments\npublic class MyCondition : ICondition<Source, Dest, bool>\n{\n    public bool Evaluate(Source src, Dest dest, bool srcMember, bool destMember, ResolutionContext ctx) => srcMember;\n}\nCreateMap<Source, Dest>().ForMember(d => d.IsActive, opt => opt.Condition<MyCondition>());","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Type guard: verify a type implements ICondition<TSource, TDestination, TMember>\nstatic bool ImplementsCondition<TSource, TDestination, TMember>(Type conditionType)\n    => conditionType.GetGenericInterface(typeof(ICondition<,,>)) != null;\n\n// Usage before configuring\nif (!ImplementsCondition<Source, Dest, bool>(typeof(MyCondition)))\n    throw new InvalidOperationException($\"{nameof(MyCondition)} must implement ICondition<Source, Dest, bool>.\");","tryCatchPattern":null,"preventionTips":["Always implement ICondition<TSource, TDestination, TMember> with the exact generic arguments matching the map.","Prefer lambda Condition(...) overloads for simple conditions to avoid interface implementation errors.","Add a unit test that builds the mapper configuration to catch interface mismatches."],"tags":["configuration","condition","interface","mapping"],"backgroundTag":null,"analyzedSha":"dfa6dd587c5854b4beee5934beb39ba6e9569b84","analyzedAt":"2026-08-13T19:56:33.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}