dotnet/efcore · error · NotImplementedException

Compound assignment not supported yet.

Error message

Compound assignment not supported yet.

What it means

Thrown by the runtime-model LINQ-to-C# translator when translating a non-public property assignment that has a registered member-access replacement (an [UnsafeAccessor]-based setter). The replacement emits a setter method call, which only supports simple assignment; any compound assignment kind (+=, -=, etc.) is not yet implemented and throws NotImplementedException.

Solutions

  1. Rewrite the compound assignment as an explicit simple assignment: x = x + y instead of x += y.
  2. Avoid compound assignment on non-public properties whose access is routed through unsafe accessors.
  3. Make the property public or use a public setter so no unsafe-accessor replacement is needed.

Example fix

// before
x += value  // compound assignment on private property
// after
x = x + value  // simple assignment
Defensive patterns

Strategy: validation

Validate before calling

// Reject compound assignment on properties with unsafe-accessor replacements
// In your expression builder, when assigning a non-public property, always emit SimpleAssignmentExpression.

Try / catch

try { translator.Translate(expr); }
catch (NotImplementedException ex) when (ex.Message.Contains("Compound assignment"))
{ throw new InvalidOperationException("Rewrite compound assignment as a simple assignment for compiled-model non-public properties.", ex); }

Prevention

When it happens

Trigger: Compiled/runtime model generation encounters a value generator or seed expression that performs a compound assignment (e.g. +=) on a non-public property for which an unsafe-accessor replacement method was registered.

Common situations: A value generator or initializer uses a compound assignment on a private/setter-replaced property; compiled model generation processes such an expression.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/9fab5293e592181f. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Design/Query/Internal/RuntimeModelLinqToCSharpSyntaxTranslator.cs:135

    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    protected override void TranslateNonPublicMemberAssignment(
        MemberExpression memberExpression,
        Expression value,
        SyntaxKind assignmentKind)
    {
        var propertyInfo = memberExpression.Member as PropertyInfo;
        var member = propertyInfo?.SetMethod ?? memberExpression.Member;
        if (_memberAccessReplacements?.TryGetValue(member, out var methodName) == true)
        {
            AddNamespace(methodName.Namespace);
            if (propertyInfo != null)
            {
                if (assignmentKind is not SyntaxKind.SimpleAssignmentExpression)
                {
                    throw new NotImplementedException("Compound assignment not supported yet.");
                }

                Result = InvocationExpression(
                    IdentifierName(methodName.Name),
                    ArgumentList(
                        SeparatedList(
                        [
                            Argument(Translate<ExpressionSyntax>(memberExpression.Expression)),
                            Argument(Translate<ExpressionSyntax>(value))
                        ])));
            }
            else
            {
                Result = AssignmentExpression(
                    assignmentKind,
                    InvocationExpression(
                        IdentifierName(methodName.Name),
                        ArgumentList(SeparatedList([Argument(Translate<ExpressionSyntax>(memberExpression.Expression))]))),

View on GitHub (pinned to 3a2006ef56)