This repository is a minimal repo of a bug in EF Core 9 related to the use of an encrypted attribute to apply a convention to encrypt attributed properties in the EF model when persisting to the DB, and to descrypt when hydrating from DB.
Bug reported at dotnet/efcore#34934
To repro
dotnet restore
dotnet run --project EFCore9Bug
results in the exception
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method43(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in C:\Users\russc\source\EFCore9Bug\EFCore9Bug\Program.cs:line 22
at Program.<Main>(String[] args)
that occurs in the .ToListAsync()
call.
It looks like the problem is in the .Select(...)
projection and specifically the projection of the property that has the Encryption value converter;
If the Encrpyted
property is removed from the projection, it succeeds.
No exception is observed with 8.0.10 EF dependencies