-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default constructor trimmed for generic argument #81720
Comments
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsDescriptionIn EF https://github.com/dotnet/efcore/blob/main/src/EFCore/Diagnostics/Internal/DiagnosticsLogger.cs is registered in DI as https://github.com/dotnet/efcore/blob/main/src/EFCore/Diagnostics/IDiagnosticsLogger`.cs Reproduction StepsSee attached Expected behaviorWhen Stack traceUnhandled Exception: System.ArgumentException: 'Microsoft.EntityFrameworkCore.DbLoggerCategory+ChangeTracking', on 'Microsoft.EntityFrameworkCore.Diagnostics.Internal.DiagnosticsLogger`1[TLoggerCategory]' violates the constraint of type 'TLoggerCategory'. at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type[], Type[], Object, ConstraintValidator.SigTypeContext) + 0x121 at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type, Type[]) + 0x44 at Internal.Reflection.Execution.ExecutionEnvironmentImplementation.TryGetConstructedGenericTypeForComponents(RuntimeTypeHandle, RuntimeTypeHandle[], RuntimeTypeHandle&) + 0x136 at System.Reflection.Runtime.TypeInfos.RuntimeConstructedGenericTypeInfo.GetRuntimeTypeHandleIfAny(RuntimeTypeInfo, RuntimeTypeInfo[]) + 0xaa at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[]) + 0x24a at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(ServiceDescriptor, Type, CallSiteChain, Int32, Boolean) + 0x199 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(Type, CallSiteChain) + 0xae at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0x10d at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type, CallSiteChain, ParameterInfo[], Boolean) + 0x70 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache, Type, Type, CallSiteChain) + 0xcf at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x180 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type, CallSiteChain) + 0x82 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0xf7 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type, CallSiteChain, ParameterInfo[], Boolean) + 0x70 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache, Type, Type, CallSiteChain) + 0xcf at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x180 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type, CallSiteChain) + 0x82 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0xf7 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) + 0x6a at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0x85 at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type, ServiceProviderEngineScope) + 0x2e at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider, Type) + 0x50 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider) + 0x29 at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies() + 0x32 at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices() + 0x13a at Program.$(String[] args) + 0x5cActual behaviorNo exceptions thrown Regression?No Known WorkaroundsAnnotating the generic parameter solves this issue public interface IDiagnosticsLogger<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TLoggerCategory> : IDiagnosticsLogger
where TLoggerCategory : LoggerCategory<TLoggerCategory>, new() ConfigurationSDK: 8.0.100-alpha.1.23073.1 Other informationNo response
|
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsDescriptionIn EF https://github.com/dotnet/efcore/blob/main/src/EFCore/Diagnostics/Internal/DiagnosticsLogger.cs is registered in DI as https://github.com/dotnet/efcore/blob/main/src/EFCore/Diagnostics/IDiagnosticsLogger`.cs Reproduction StepsSee attached Expected behaviorNo exceptions thrown Actual behaviorWhen Stack traceUnhandled Exception: System.ArgumentException: 'Microsoft.EntityFrameworkCore.DbLoggerCategory+ChangeTracking', on 'Microsoft.EntityFrameworkCore.Diagnostics.Internal.DiagnosticsLogger`1[TLoggerCategory]' violates the constraint of type 'TLoggerCategory'. at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type[], Type[], Object, ConstraintValidator.SigTypeContext) + 0x121 at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type, Type[]) + 0x44 at Internal.Reflection.Execution.ExecutionEnvironmentImplementation.TryGetConstructedGenericTypeForComponents(RuntimeTypeHandle, RuntimeTypeHandle[], RuntimeTypeHandle&) + 0x136 at System.Reflection.Runtime.TypeInfos.RuntimeConstructedGenericTypeInfo.GetRuntimeTypeHandleIfAny(RuntimeTypeInfo, RuntimeTypeInfo[]) + 0xaa at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[]) + 0x24a at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(ServiceDescriptor, Type, CallSiteChain, Int32, Boolean) + 0x199 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(Type, CallSiteChain) + 0xae at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0x10d at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type, CallSiteChain, ParameterInfo[], Boolean) + 0x70 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache, Type, Type, CallSiteChain) + 0xcf at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x180 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type, CallSiteChain) + 0x82 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0xf7 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type, CallSiteChain, ParameterInfo[], Boolean) + 0x70 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache, Type, Type, CallSiteChain) + 0xcf at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x180 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type, CallSiteChain) + 0x82 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0xf7 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) + 0x6a at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0x85 at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type, ServiceProviderEngineScope) + 0x2e at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider, Type) + 0x50 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider) + 0x29 at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies() + 0x32 at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices() + 0x13a at Program.$(String[] args) + 0x5cRegression?No Known WorkaroundsAnnotating the generic parameter solves this issue public interface IDiagnosticsLogger<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TLoggerCategory> : IDiagnosticsLogger
where TLoggerCategory : LoggerCategory<TLoggerCategory>, new() ConfigurationSDK: 8.0.100-alpha.1.23073.1 Other informationNo response
|
Confirmed that this is NativeAOT only issue. Trimming alone works fine (since linker correctly handles the new constraint). |
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsDescriptionIn EF https://github.com/dotnet/efcore/blob/main/src/EFCore/Diagnostics/Internal/DiagnosticsLogger.cs is registered in DI as https://github.com/dotnet/efcore/blob/main/src/EFCore/Diagnostics/IDiagnosticsLogger`.cs Reproduction StepsSee attached Expected behaviorNo exceptions thrown Actual behaviorWhen Stack traceUnhandled Exception: System.ArgumentException: 'Microsoft.EntityFrameworkCore.DbLoggerCategory+ChangeTracking', on 'Microsoft.EntityFrameworkCore.Diagnostics.Internal.DiagnosticsLogger`1[TLoggerCategory]' violates the constraint of type 'TLoggerCategory'. at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type[], Type[], Object, ConstraintValidator.SigTypeContext) + 0x121 at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type, Type[]) + 0x44 at Internal.Reflection.Execution.ExecutionEnvironmentImplementation.TryGetConstructedGenericTypeForComponents(RuntimeTypeHandle, RuntimeTypeHandle[], RuntimeTypeHandle&) + 0x136 at System.Reflection.Runtime.TypeInfos.RuntimeConstructedGenericTypeInfo.GetRuntimeTypeHandleIfAny(RuntimeTypeInfo, RuntimeTypeInfo[]) + 0xaa at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[]) + 0x24a at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(ServiceDescriptor, Type, CallSiteChain, Int32, Boolean) + 0x199 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(Type, CallSiteChain) + 0xae at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0x10d at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type, CallSiteChain, ParameterInfo[], Boolean) + 0x70 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache, Type, Type, CallSiteChain) + 0xcf at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x180 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type, CallSiteChain) + 0x82 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0xf7 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type, CallSiteChain, ParameterInfo[], Boolean) + 0x70 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache, Type, Type, CallSiteChain) + 0xcf at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x180 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type, CallSiteChain) + 0x82 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0xf7 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) + 0x6a at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0x85 at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type, ServiceProviderEngineScope) + 0x2e at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider, Type) + 0x50 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider) + 0x29 at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies() + 0x32 at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices() + 0x13a at Program.$(String[] args) + 0x5cRegression?No Known WorkaroundsAnnotating the generic parameter solves this issue public interface IDiagnosticsLogger<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TLoggerCategory> : IDiagnosticsLogger
where TLoggerCategory : LoggerCategory<TLoggerCategory>, new() ConfigurationSDK: 8.0.100-alpha.1.23073.1 Other informationNo response
|
This is done by treating the new constraint as a data flow annotation `PublicParameterlessConstructor` (which are supposed to be identical). The rest falls out from this change since all of the validation and marking will automatically kick in. This change causes more methods to go through data flow (since that's what will actually perform the constraint validation/marking). I tested this on the ASP.NET API AOT template. Before this change it ran ~620 methods through data flow. With this change that number goes up to ~2100. The problem is tracked by #82603. I measured compiler perf but didn't see any noticeable changes. Current thinking is that ~2100 is still not that much and most of those methods are pretty small and thus cheap to run data flow on. Fixes #81720 - note that the repro still fails on AOT with this fix, but the failure is different (`System.InvalidOperationException: Sequence contains no matching element`). I verified that the missing .ctor is present in the app with the fix.
Description
In EF https://github.com/dotnet/efcore/blob/main/src/EFCore/Diagnostics/Internal/DiagnosticsLogger.cs is registered in DI as https://github.com/dotnet/efcore/blob/main/src/EFCore/Diagnostics/IDiagnosticsLogger`.cs
Reproduction Steps
See attached
DITest.zip
Expected behavior
No exceptions thrown
Actual behavior
When
IDiagnosticsLogger<
ChangeTracking>
is resolved the following exception is thrown in NativeAOT mode:Stack trace
Unhandled Exception: System.ArgumentException: 'Microsoft.EntityFrameworkCore.DbLoggerCategory+ChangeTracking', on 'Microsoft.EntityFrameworkCore.Diagnostics.Internal.DiagnosticsLogger`1[TLoggerCategory]' violates the constraint of type 'TLoggerCategory'. at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type[], Type[], Object, ConstraintValidator.SigTypeContext) + 0x121 at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type, Type[]) + 0x44 at Internal.Reflection.Execution.ExecutionEnvironmentImplementation.TryGetConstructedGenericTypeForComponents(RuntimeTypeHandle, RuntimeTypeHandle[], RuntimeTypeHandle&) + 0x136 at System.Reflection.Runtime.TypeInfos.RuntimeConstructedGenericTypeInfo.GetRuntimeTypeHandleIfAny(RuntimeTypeInfo, RuntimeTypeInfo[]) + 0xaa at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[]) + 0x24a at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(ServiceDescriptor, Type, CallSiteChain, Int32, Boolean) + 0x199 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(Type, CallSiteChain) + 0xae at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0x10d at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type, CallSiteChain, ParameterInfo[], Boolean) + 0x70 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache, Type, Type, CallSiteChain) + 0xcf at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x180 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type, CallSiteChain) + 0x82 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0xf7 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type, CallSiteChain, ParameterInfo[], Boolean) + 0x70 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache, Type, Type, CallSiteChain) + 0xcf at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor, Type, CallSiteChain, Int32) + 0x180 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type, CallSiteChain) + 0x82 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain) + 0xf7 at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type, CallSiteChain) + 0x51 at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) + 0x6a at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0x85 at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type, ServiceProviderEngineScope) + 0x2e at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider, Type) + 0x50 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider) + 0x29 at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies() + 0x32 at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices() + 0x13a at Program.$(String[] args) + 0x5cRegression?
No
Known Workarounds
Annotating the generic parameter solves this issue
Configuration
SDK: 8.0.100-alpha.1.23073.1
Runtime: 8.0.0-preview.2.23081.5
Other information
No response
The text was updated successfully, but these errors were encountered: