dotnet/efcore · error · NotImplementedException
MemberInit: incompatible MemberListBinding
Error message
MemberInit: incompatible MemberListBinding
What it means
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").
Source
Thrown at src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs:2557
}
var liftedStatementsPosition = _liftedState.Statements.Count;
VisitMemberBinding(binding);
initializerExpressions.Add((AssignmentExpressionSyntax)Result!);
if (_liftedState.Statements.Count > liftedStatementsPosition)
{
// TODO: This is tricky because of the recursive nature of MemberMemberBinding
throw new NotImplementedException("MemberInit: lifted statements");
}
}
if (incompatibleListBindings is not null)
{
// TODO: Lift the instantiation and add extra statements to add the incompatible bindings after that
throw new NotImplementedException("MemberInit: incompatible MemberListBinding");
}
Result = objectCreation.WithInitializer(
InitializerExpression(
SyntaxKind.ObjectInitializerExpression,
SeparatedList<ExpressionSyntax>(initializerExpressions)));
return memberInit;
}
/// <inheritdoc />
protected override Expression VisitListInit(ListInitExpression listInit)
{
var objectCreation = Translate<ObjectCreationExpressionSyntax>(listInit.NewExpression);
List<ElementInit>? incompatibleListBindings = null;
var initializerExpressions = new List<ExpressionSyntax>(listInit.Initializers.Count);View on GitHub (pinned to dbf9771522)
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.
Example fix
// before
new X { Items = { a, b } } // where Items is a custom collection with Add(int,string)
// after
var x = new X(); x.Items.Add(a); x.Items.Add(b); // explicit adds after construction Defensive patterns
Strategy: validation
Validate before calling
// Flag collection member bindings whose member is not IEnumerable-with-single-arg-Add
protected override Expression VisitMemberInit(MemberInitExpression mi) {
foreach (var b in mi.Bindings.OfType<MemberListBinding>()) {
var t = b.Member.GetMemberType();
if (!typeof(IEnumerable).IsAssignableFrom(t)
|| b.Initializers.Any(e => e.AddMethod.Name != "Add" || e.Arguments.Count != 1)) Found = true;
}
return mi;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Custom collection types with Add(int, string) signatures; non-IEnumerable members initialized with list bindings inside compiled expressions.
Related errors
- ListInit: lifted statements
- ListInit: incompatible ElementInit
- MemberInit: lifted statements
- DebugInfo nodes are not supporting when translating expressi
- Null argument in VisitLabelTarget
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/d250ff5cb48f57db.
Report an issue: GitHub.