{"record":{"id":"9fab5293e592181f","repo":"dotnet/efcore","slug":"compound-assignment-not-supported-yet","errorCode":null,"errorMessage":"Compound assignment not supported yet.","messagePattern":"Compound assignment not supported yet\\.","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/RuntimeModelLinqToCSharpSyntaxTranslator.cs","lineNumber":135,"sourceCode":"    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    protected override void TranslateNonPublicMemberAssignment(\n        MemberExpression memberExpression,\n        Expression value,\n        SyntaxKind assignmentKind)\n    {\n        var propertyInfo = memberExpression.Member as PropertyInfo;\n        var member = propertyInfo?.SetMethod ?? memberExpression.Member;\n        if (_memberAccessReplacements?.TryGetValue(member, out var methodName) == true)\n        {\n            AddNamespace(methodName.Namespace);\n            if (propertyInfo != null)\n            {\n                if (assignmentKind is not SyntaxKind.SimpleAssignmentExpression)\n                {\n                    throw new NotImplementedException(\"Compound assignment not supported yet.\");\n                }\n\n                Result = InvocationExpression(\n                    IdentifierName(methodName.Name),\n                    ArgumentList(\n                        SeparatedList(\n                        [\n                            Argument(Translate<ExpressionSyntax>(memberExpression.Expression)),\n                            Argument(Translate<ExpressionSyntax>(value))\n                        ])));\n            }\n            else\n            {\n                Result = AssignmentExpression(\n                    assignmentKind,\n                    InvocationExpression(\n                        IdentifierName(methodName.Name),\n                        ArgumentList(SeparatedList([Argument(Translate<ExpressionSyntax>(memberExpression.Expression))]))),","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/RuntimeModelLinqToCSharpSyntaxTranslator.cs#L117-L153","documentation":"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.","triggerScenarios":"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.","commonSituations":"A value generator or initializer uses a compound assignment on a private/setter-replaced property; compiled model generation processes such an expression.","solutions":["Rewrite the compound assignment as an explicit simple assignment: x = x + y instead of x += y.","Avoid compound assignment on non-public properties whose access is routed through unsafe accessors.","Make the property public or use a public setter so no unsafe-accessor replacement is needed."],"exampleFix":"// before\nx += value  // compound assignment on private property\n// after\nx = x + value  // simple assignment","handlingStrategy":"validation","validationCode":"// Reject compound assignment on properties with unsafe-accessor replacements\n// In your expression builder, when assigning a non-public property, always emit SimpleAssignmentExpression.","typeGuard":null,"tryCatchPattern":"try { translator.Translate(expr); }\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"Compound assignment\"))\n{ throw new InvalidOperationException(\"Rewrite compound assignment as a simple assignment for compiled-model non-public properties.\", ex); }","preventionTips":["Use x = x + y instead of x += y for non-public property assignments in compiled-model expressions.","Make properties public when possible to bypass unsafe-accessor routing.","Audit value-generator/seed expressions for compound assignments."],"tags":["compiled-model","expression-trees","unsafe-accessors","assignment"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}