-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Bug description
I cannot get a small AOT sample project working with ef core.
I get many errors when publishing involving both the generated compiled model and the entityframeworkcore nuget packages and dependencies.
IL3050:
EfAotTestProject.CompiledModels.MyEntityEntityType.Create(RuntimeModel,RuntimeEntityType): Using member 'System.Enum.GetValues(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. It might not be possible to create an array of the enum type at runtime. Use the GetValues overload or the GetValuesAsUnderlyingType method instead.
This was already brought up as an issue here #34057 but it is closed as completed. However, I think it should be reopened as I'm still getting the issue on 10.0 rc1 version of ef core.
IL2037:
Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteUpdateAsync(IQueryable1<TSource>,Action
1<UpdateSettersBuilder`1>,CancellationToken): No members were resolved for 'ExecuteUpdate1(System.Linq.IQueryable{
1},System.Collections.Generic.IReadOnlyList{ITuple})' on type 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions'.
The errors involving the ef packages are less specific. They look like this
/home/ubuntu/.nuget/packages/microsoft.entityframeworkcore/10.0.0-rc.1.25451.107/lib/net10.0/Microsoft.EntityFrameworkCore.dll : error IL2104: Assembly 'Microsoft.EntityFrameworkCore' produced trim warnings. For more information see https://aka.ms/il2104
The packages with trim warnings are
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Relational
Microsoft.EntityFrameworkCore.Sqlite
I publish works if I try it a second time, but unsurprisingly I get missing code errors when I run the code
Your code
Stack traces
Unhandled exception. System.NotSupportedException: 'Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer.CreateDefault[System.Guid](System.Boolean)' is missing native code. MethodInfo.MakeGenericMethod() is not compatible with AOT compilation. Inspect and fix AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility
at System.Reflection.Runtime.MethodInfos.RuntimeNamedMethodInfo`1.GetUncachedMethodInvoker(RuntimeTypeInfo[], MemberInfo) + 0x2a
at System.Reflection.Runtime.MethodInfos.RuntimeMethodInfo.Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) + 0x3f
at Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer.CreateDefault(Type type, Boolean favorStructuralComparisons) + 0xaa
at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue&, TParam, Func`2) + 0x1d
at Microsoft.EntityFrameworkCore.Metadata.RuntimeProperty.<>c.<GetKeyValueComparer>b__52_0(RuntimeProperty property) + 0x31
at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue&, TParam, Func`2) + 0x1d
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.SimplePrincipalKeyValueFactory`1..ctor(IKey) + 0x6e
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.KeyValueFactoryFactory.CreateSimpleNonNullableFactory[TKey](IKey key) + 0x31
at EfAotTestProject.CompiledModels.MyEntityEntityType.CreateAnnotations(RuntimeEntityType) + 0x1b9
at EfAotTestProject.CompiledModels.MyDbContextModel.Initialize() + 0x1e
at System.Threading.Thread.StartThread(IntPtr) + 0x131
at System.Threading.Thread.ThreadEntryPoint(IntPtr) + 0x19
Verbose output
EF Core version
10.0.0-rc.1.25451.107
Database provider
Microsoft.EntityFrameworkCore.Sqlite
Target framework
.NET 10.0 rc1
Operating system
Ubuntu 24.04.1 LTS (WSL)
IDE
VS Code