Background and Motivation
There are some "global" dynamic dependencies that can't be identified by managed IL methods, constructors, or fields. For example, some members on core types, like Task, ThreadPool, etc, are only necessary for debuggers to call. They are not called by any code in our libraries nor are they public. In order for the ILLinker to preserve these private members, we need to mark them with a [DynamicDependency], but the issue is there isn't a good place to put the attribute, since there are no callsites.
So instead, we need to place the [DynamicDependency] on the class/struct itself, meaning "if this type is preserved at all, then also preserve this member".
See the discussion here: #37288 (comment)
Proposed API
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(
- AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method,
+ AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Struct,
AllowMultiple = true, Inherited = false)]
public sealed class DynamicDependencyAttribute : Attribute
Usage Examples
namespace System.Threading.Tasks
{
[DynamicDependency("get_ParentForDebugger")]
[DynamicDependency("get_StateFlagsForDebugger")]
[DynamicDependency("GetDelegateContinuationsForDebugger")]
[DynamicDependency("SetNotificationForWaitCompletion")]
[DynamicDependency("GetActiveTaskFromId")] // used by VS Tasks Window
public class Task
{
...
}
Alternative Designs
Risks
We initially didn't want to allow [DynamicDependency] on a type itself because we were concerned that users could make a mistake, and too many members will be kept unnecessarily.
cc @vitek-karas @MichalStrehovsky @marek-safar @joperezr @layomia
Background and Motivation
There are some "global" dynamic dependencies that can't be identified by managed IL methods, constructors, or fields. For example, some members on core types, like
Task,ThreadPool, etc, are only necessary for debuggers to call. They are not called by any code in our libraries nor are they public. In order for the ILLinker to preserve these private members, we need to mark them with a[DynamicDependency], but the issue is there isn't a good place to put the attribute, since there are no callsites.So instead, we need to place the
[DynamicDependency]on the class/struct itself, meaning "if this type is preserved at all, then also preserve this member".See the discussion here: #37288 (comment)
Proposed API
namespace System.Diagnostics.CodeAnalysis { [AttributeUsage( - AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method, + AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)] public sealed class DynamicDependencyAttribute : AttributeUsage Examples
Alternative Designs
Risks
We initially didn't want to allow
[DynamicDependency]on a type itself because we were concerned that users could make a mistake, and too many members will be kept unnecessarily.cc @vitek-karas @MichalStrehovsky @marek-safar @joperezr @layomia