Repository navigation
Description
Generating a Native AOT compiled model fails for any model with a range, multirange or value set property. That form is what dotnet ef dbcontext optimize --nativeaot writes, and --precompile-queries needs it. It fails loudly before any code is written:
System.InvalidOperationException: The type mapping used is incompatible with a compiled model.
The mapping type must have a 'public static readonly ValueRangeTypeMapping<DateRange, DateOnly> ValueRangeTypeMapping<DateRange, DateOnly>.Default' property.
Measured on main (d073eb6) with the in-process generator CompiledModelJsonTests runs (#43), setting CompiledModelCodeGenerationOptions.ForNativeAot = true. The standard compiled model (dotnet ef dbcontext optimize) works: it carries no type mappings and resolves them through the plugin at run time. #43's test covers every discovered type in that form.
What this means for the JSON reader/writers. LiteralJsonValueReaderWriter and the three YearMonth reader/writers are public, with ConstructorExpression pointing at a static Instance, "because a compiled model re-creates the reader/writer through ConstructorExpression". Only the Native AOT form reads ConstructorExpression, and that form can't be generated. So the design has never run. Both seeds below pass every suite today, including #43's test, because the standard form never consults them:
ConstructorExpression => Expression.New(<the private constructor>). Generated code could not construct the reader/writer (CS0122).YearMonthRangeJsonValueReaderWriter.InstancePropertypointing atLiteralJsonValueReaderWriter<YearMonthRange>.Instance. A Native AOT model would write YearMonthRange as its own literal where the runtime model writes the month-aligned daterange.
Options.
- Give every plugin type mapping (
ValueRangeTypeMapping,ValueRangeSetTypeMapping,ValueSetTypeMapping, the bridged element mappings) theDefaultEF Core needs, and whatever else the Native AOT generator asks for next. Then run Test JSON-column readers and writers through a compiled model #43's test withForNativeAot = trueand register it as an oracle with the two seeds above. - Document that the EF Core packages support the standard compiled model but not the Native AOT one. That fits the EF packages not claiming AOT compatibility (
PackagingConventionTests). TheInstance/ConstructorExpressioncomments would then say they are for the Native AOT form.
Not silent: generation throws.
Activity
CaffeinatedCoder commentedon Oct 18, 2026
Moved to the backlog (#83). Additions are frozen for 10.0.0 (epic #58, 2026-10-18), and this fails loudly at design time, so it can ship in a 10.x minor within the additions window (#178). It supersedes #42, which asked for the same static
Defaultwithout the measurement; #42 is closed as a duplicate.CaffeinatedCoder commentedon Oct 18, 2026
Related but separate: #47 now designs
CodoMetis.ValueRanges.Npgsql, an AOT-safe path through raw Npgsql that doesn't need EF Core or this issue.CaffeinatedCoder commentedon Oct 18, 2026
Takes over the obligation #43's test can't hold (pre-tag analysis #179): the
ConstructorExpressionof the JSON reader/writers is consulted only by--nativeaotcompiled models. When this is fixed, its test must fail withLiteralJsonValueReaderWriter.ConstructorExpression => throw new NotSupportedException()seeded.