-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
When marking fields for reflection, ILLink usually doesn't treat compiler-generated backing fields specially. They will be marked as any other field if referenced due to DAMT annotations, for example.
However, there is one case where we have an optimization to avoid marking these fields if the corresponding property is not marked - that happens for root descriptors which reference the field using preserve="fields".
There is a similar issue #85042 about warnings for reflection access to compiler-generated code, where we decided we would not try to produce warnings in this case. I'm not sure it would be feasible to avoid marking the compiler-generated methods in that case, because I think dependency injection inspects compiler-generated code via reflection.
But we might consider not marking compiler-generated backing fields, as suggested by @jtschuster in https://github.com/dotnet/runtime/pull/102850/files#r1619568383. The current optimization looks for a field name ending with >k__BackingField:
| if (markBackingFieldsOnlyIfPropertyMarked && field.Name.EndsWith (">k__BackingField", StringComparison.Ordinal)) { |
Maybe a more robust way to do this would be to look for CompilerGeneratedAttribute on the field.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status