-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Closed
Copy link
Labels
area-Tools-ILLink.NET linker development as well as trimming analyzers.NET linker development as well as trimming analyzers
Milestone
Description
Description
The linker does not respect DynamicallyAccessedMembers attributes on parameters within a primary constructor.
internal sealed class TypeBasedOpenApiDocumentTransformer([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type transformerType) : IOpenApiDocumentTransformer
{
private readonly ObjectFactory _transformerFactory = ActivatorUtilities.CreateFactory(transformerType, []);
}Note: this issue appears to repro specifically on the linker configuration used by ASP.NET Core's LinkabilityChecker tool. A more simplified repro on a console app doesn't share the same issue.
Reproduction Steps
git clone --recursive https://github.com/dotnet/aspnetcoregit checkout origin/safia/linker-primconstructors-bug./restore.shcd src/Tools/LinkabilityCheckerdotnet run- Observe linker exception.
Expected behavior
No linker exception is raised.
Actual behavior
Trim analysis warning IL2077: Microsoft.AspNetCore.OpenApi.TypeBasedOpenApiDocumentTransformer.TypeBasedOpenApiDocumentTransformer(Type):
'instanceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to
'Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateFactory(Type, Type[])'. The field
'Microsoft.AspNetCore.OpenApi.TypeBasedOpenApiDocumentTransformer.<transformerType>P' does not have matching
annotations. The source value must declare at least the same requirements as those declared on the target location it is
assigned to.
Regression?
No response
Known Workarounds
Explicitly defining a transformerType field with the DAM annotations resolves the issue.
Configuration
$ dotnet --info 11:38:54
.NET SDK:
Version: 9.0.100-preview.5.24229.2
Commit: d301a122c4
Workload version: 9.0.100-manifests.90bb8117
MSBuild version: 17.11.0-preview-24222-11+9cdb3615a
Other information
No response
eerhardt
Metadata
Metadata
Assignees
Labels
area-Tools-ILLink.NET linker development as well as trimming analyzers.NET linker development as well as trimming analyzers
Type
Projects
Status
High Priority