dotnet / dotnet/linker

Support marking a string as a Type, but don't require members to be accessed on it

Open
#1,878 0 comments 0 reactions 0 assignees View on GitHub
area-Linker: DataFlow
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

In `System.ComponentModel.TypeConverter`, there are a few instances where it will call `Type.GetType(string)`, and then use the Type to pass into other methods.

An example is the `ProvidePropertyAttribute` - https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.providepropertyattribute

This attribute can take a `string receiverTypeName` [parameter in its constructor](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.providepropertyattribute.-ctor?view=net-5.0#System_ComponentModel_ProvidePropertyAttribute__ctor_System_String_System_String_). In order to support this, we need to mark that parameter as `DynamicallyAccessedMembers` so the linker will see that the Type is being used and not trim the Type. However, in order to use `DynamicallyAccessedMembers`, we need to specify a `DynamicallyAccessedMemberTypes` enum. Putting `DynamicallyAccessedMemberTypes.None` should mark the Type as being preserved, but not mark any of its members.

This also applies to the `EditorAttribute`'s `string? baseTypeName` parameter. The code calls `Type.GetType` using this string, but doesn't reflect on anything else on the Type. The Type needs to be preserved, but not necessarily any of its members.

For now I've been using `DynamicallyAccessedMemberTypes.PublicParameterlessConstructor` to preserve these Types.

cc @vitek-karas @MichalStrehovsky @marek-safar

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.