Skip to content

DynamicallyAccessedMembers annotations do not seem to be working on type delcarations. #113650

@eiriktsarpalis

Description

@eiriktsarpalis

Consider the following application:

using System.Diagnostics.CodeAnalysis;

Test(typeof(MyPoco));
static void Test(Type type) => Activator.CreateInstance(type);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
class MyPoco;

I would have expected that this would instruct the linker to preserve the default constructor for MyPoco, however when I publish to AOT I get the error:

Unhandled exception. System.MissingMethodException: No parameterless constructor defined for type 'MyPoco'.
   at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0x198
   at Program.<Main>$(String[] args) + 0x2c

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILLink.NET linker development as well as trimming analyzersquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions