-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
area-Tools-ILLink.NET linker development as well as trimming analyzers.NET linker development as well as trimming analyzers
Milestone
Description
The ILLink Roslyn Analyzer has some logic to handle dynamic object invocations, producing RequiresUnreferencedCode warnings, for example:
dynamic s = "hello";
s.DoSomething();
This produces IL2026
at the callsite.
This compiles into something like the following:
object arg = "hello";
if (<>o__0.<>p__0 == null)
{
Type typeFromHandle = typeof(C);
CSharpArgumentInfo[] array = new CSharpArgumentInfo[1];
array[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null);
<>o__0.<>p__0 = CallSite<Action<CallSite, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(CSharpBinderFlags.ResultDiscarded, "DoSomething", null, typeFromHandle, array));
}
<>o__0.<>p__0.Target(<>o__0.<>p__0, arg);
ILLink also produces IL2026 due to InvokeMember being annotated with RequiresUnreferencedCode.
ILCompiler additionaly produces IL3050 due to CallSite.Create being annotated with RequiresDynamicCode. We should consider ways to produce the same warning in the ILLink Roslyn analyzer.
#94236 is improving the analyzer's coverage of the RequiresUnreferencedCode warnings by treating dynamic invocations as calls to RuntimeBinder methods. Perhaps we could do the same by including an additional call to CallSite.Create.
Metadata
Metadata
Assignees
Labels
area-Tools-ILLink.NET linker development as well as trimming analyzers.NET linker development as well as trimming analyzers
Type
Projects
Status
No status