{"record":{"id":"d250ff5cb48f57db","repo":"dotnet/efcore","slug":"memberinit-incompatible-memberlistbinding","errorCode":null,"errorMessage":"MemberInit: incompatible MemberListBinding","messagePattern":"MemberInit: incompatible MemberListBinding","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":2557,"sourceCode":"            }\n\n            var liftedStatementsPosition = _liftedState.Statements.Count;\n\n            VisitMemberBinding(binding);\n\n            initializerExpressions.Add((AssignmentExpressionSyntax)Result!);\n\n            if (_liftedState.Statements.Count > liftedStatementsPosition)\n            {\n                // TODO: This is tricky because of the recursive nature of MemberMemberBinding\n                throw new NotImplementedException(\"MemberInit: lifted statements\");\n            }\n        }\n\n        if (incompatibleListBindings is not null)\n        {\n            // TODO: Lift the instantiation and add extra statements to add the incompatible bindings after that\n            throw new NotImplementedException(\"MemberInit: incompatible MemberListBinding\");\n        }\n\n        Result = objectCreation.WithInitializer(\n            InitializerExpression(\n                SyntaxKind.ObjectInitializerExpression,\n                SeparatedList<ExpressionSyntax>(initializerExpressions)));\n\n        return memberInit;\n    }\n\n    /// <inheritdoc />\n    protected override Expression VisitListInit(ListInitExpression listInit)\n    {\n        var objectCreation = Translate<ObjectCreationExpressionSyntax>(listInit.NewExpression);\n\n        List<ElementInit>? incompatibleListBindings = null;\n\n        var initializerExpressions = new List<ExpressionSyntax>(listInit.Initializers.Count);","sourceCodeStart":2539,"sourceCodeEnd":2575,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L2539-L2575","documentation":"C# collection-initializer syntax requires an IEnumerable member with a single-argument Add method. If a MemberListBinding (collection member binding) does not fit — the member is not IEnumerable, or its Add method takes multiple arguments or is not named Add — the translator cannot lift those calls yet and throws NotImplementedException(\"MemberInit: incompatible MemberListBinding\").","triggerScenarios":"An object initializer binding a collection member whose Add method has multiple parameters or is not named Add, or whose member type is not IEnumerable.","commonSituations":"Custom collection types with Add(int, string) signatures; non-IEnumerable members initialized with list bindings inside compiled expressions.","solutions":["Use collection member types that implement IEnumerable with a single-argument Add.","Initialize the collection after construction via explicit Add calls rather than a member list binding.","Avoid collection member bindings on custom-add collections in precompiled queries."],"exampleFix":"// before\nnew X { Items = { a, b } }  // where Items is a custom collection with Add(int,string)\n// after\nvar x = new X(); x.Items.Add(a); x.Items.Add(b); // explicit adds after construction","handlingStrategy":"validation","validationCode":"// Flag collection member bindings whose member is not IEnumerable-with-single-arg-Add\nprotected override Expression VisitMemberInit(MemberInitExpression mi) {\n    foreach (var b in mi.Bindings.OfType<MemberListBinding>()) {\n        var t = b.Member.GetMemberType();\n        if (!typeof(IEnumerable).IsAssignableFrom(t)\n            || b.Initializers.Any(e => e.AddMethod.Name != \"Add\" || e.Arguments.Count != 1)) Found = true;\n    }\n    return mi;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use IEnumerable collections with a single-argument Add for member list bindings.","Initialize custom collections via explicit Add calls after construction.","Avoid multi-argument Add collections in member initializers."],"tags":["ef-core","linq","expression-tree","object-init","collections"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}