You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Precompiled queries code produces nullable annotation warning on build #37996
Precompiled query code can have nullable annotations:
public static TSource? Query1_FirstOrDefault1<TSource>(this global::System.Linq.IQueryable<TSource> source)
Building it leads to a warning:
/workspaces/ef-play/nullwarn/Generated/Program.EFInterceptors.Context.cs(32,30): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.
It seems the only way to ignore this warning is to disable it for the whole project.
---Model.cs
public class Blog
{
public int Id {get;set;}}---Context.cs
using Microsoft.EntityFrameworkCore;publicclassContext:DbContext{publicDbSet<Blog>Blogs{get;set;}=null!;protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){base.OnConfiguring(optionsBuilder);optionsBuilder.UseSqlite("Data Source=tmp.db");}}---Program.cs
using var context =newContext();_=context.Blogs.FirstOrDefault();
Thanks for raising this. I'm putting on the backlog as we're looking at better ways to support NativeAOT, but at some point we'll do a push and I'll take a look at fixing this.
I'd like to fix this if it's open for a community PR.
The generated file starts with // <auto-generated />, so the compiler disables the nullable context for it, but the interceptor signatures keep the nullable annotations from the operator signatures (e.g. TSource? for FirstOrDefault). That gives CS8669 whatever the project's Nullable setting is.
I tried emitting #nullable enable annotations after the #pragma warning disable EF9100 line. That makes the annotations valid without turning on nullable warnings for the rest of the generated code.
For a test, I made PrecompiledQueryTestHelpers fail on CS8669 in the generated files. On main that fails 33 of the SQLite precompiled query tests, and with the change they pass. Does that sound OK? If so I'll open a PR.
Activity
roji commentedon Mar 25, 2026
Thanks for raising this. I'm putting on the backlog as we're looking at better ways to support NativeAOT, but at some point we'll do a push and I'll take a look at fixing this.
nurullahturkoglu commentedon Oct 10, 2026
I'd like to fix this if it's open for a community PR.
The generated file starts with
// <auto-generated />, so the compiler disables the nullable context for it, but the interceptor signatures keep the nullable annotations from the operator signatures (e.g.TSource?forFirstOrDefault). That gives CS8669 whatever the project's Nullable setting is.I tried emitting
#nullable enable annotationsafter the#pragma warning disable EF9100line. That makes the annotations valid without turning on nullable warnings for the rest of the generated code.For a test, I made
PrecompiledQueryTestHelpersfail on CS8669 in the generated files. On main that fails 33 of the SQLite precompiled query tests, and with the change they pass. Does that sound OK? If so I'll open a PR.