Skip to content

Passing null args and BindingFlags.Public to Activator.CreateInstance is showing warnings even though type has DAM.PublicParameterlessConstructor #2110

@krwq

Description

@krwq

Calling:

Activator.CreateInstance(GetType(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, null, CultureInfo.InvariantCulture, null);

when class which calls GetType() is marked with:

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]

is showing warnings. On top of that the warning seems to be a bit broken:

Trim analysis warning IL2072: System.Data.Common.DataAdapter.CloneInternals(): '#0' argument does not satisfy  in call to 'System.Object System.Activator::CreateInstance(System.Type,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object[],System.Globalization.CultureInfo,System.Object[])'. The return value of method 'System.Type System.Object::GetType()' 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.

note that message is missing what the argument should satisfy.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions