Skip to content
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

Closed
AndriySvyryd opened this issue Feb 6, 2023 · 6 comments · Fixed by #82818
Closed

Default constructor trimmed for generic argument #81720

AndriySvyryd opened this issue Feb 6, 2023 · 6 comments · Fixed by #82818

Comments

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Feb 6, 2023

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) + 0x5c

Regression?

No

Known Workarounds

Annotating the generic parameter solves this issue

public interface IDiagnosticsLogger<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TLoggerCategory> : IDiagnosticsLogger
    where TLoggerCategory : LoggerCategory<TLoggerCategory>, new()

Configuration

SDK: 8.0.100-alpha.1.23073.1
Runtime: 8.0.0-preview.2.23081.5

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 6, 2023
@ghost
Copy link

ghost commented Feb 6, 2023

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

Issue Details

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

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) + 0x5c

Actual behavior

No exceptions thrown

Regression?

No

Known Workarounds

Annotating the generic parameter solves this issue

public interface IDiagnosticsLogger<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TLoggerCategory> : IDiagnosticsLogger
    where TLoggerCategory : LoggerCategory<TLoggerCategory>, new()

Configuration

SDK: 8.0.100-alpha.1.23073.1
Runtime: 8.0.0-preview.2.23081.5

Other information

No response

Author: AndriySvyryd
Assignees: -
Labels:

untriaged, area-Extensions-DependencyInjection

Milestone: -

@AndriySvyryd
Copy link
Member Author

cc: @MichalStrehovsky @vitek-karas

@AndriySvyryd AndriySvyryd added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Feb 6, 2023
@ghost
Copy link

ghost commented Feb 6, 2023

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

Issue Details

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) + 0x5c

Regression?

No

Known Workarounds

Annotating the generic parameter solves this issue

public interface IDiagnosticsLogger<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TLoggerCategory> : IDiagnosticsLogger
    where TLoggerCategory : LoggerCategory<TLoggerCategory>, new()

Configuration

SDK: 8.0.100-alpha.1.23073.1
Runtime: 8.0.0-preview.2.23081.5

Other information

No response

Author: AndriySvyryd
Assignees: -
Labels:

untriaged, area-Extensions-DependencyInjection, area-Tools-ILLink

Milestone: -

@vitek-karas
Copy link
Member

This sounds a lot like a duplicate of #80037.
Although it might be a bit more complicated due to it going through DI, so probably also related to #81358

@vitek-karas
Copy link
Member

Confirmed that this is NativeAOT only issue. Trimming alone works fine (since linker correctly handles the new constraint).
This is obviously something we need to fix - I'll look into this next.

@ghost
Copy link

ghost commented Feb 8, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

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) + 0x5c

Regression?

No

Known Workarounds

Annotating the generic parameter solves this issue

public interface IDiagnosticsLogger<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TLoggerCategory> : IDiagnosticsLogger
    where TLoggerCategory : LoggerCategory<TLoggerCategory>, new()

Configuration

SDK: 8.0.100-alpha.1.23073.1
Runtime: 8.0.0-preview.2.23081.5

Other information

No response

Author: AndriySvyryd
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr, area-Tools-ILLink

Milestone: -

@MichalStrehovsky MichalStrehovsky removed the area-Tools-ILLink .NET linker development as well as trimming analyzers label Feb 8, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 1, 2023
@agocke agocke added this to AppModel Mar 6, 2023
vitek-karas added a commit that referenced this issue Mar 8, 2023
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.
@ghost ghost removed in-pr There is an active PR which will close this issue when it is merged untriaged New issue has not been triaged by the area owner labels Mar 8, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants