Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ILLink analyzer] Analyzer doesn't produce RequiresDynamicCode warnings for dynamic objects #94427

@sbomer

Description

@sbomer

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

No one assigned

    Labels

    area-Tools-ILLink.NET linker development as well as trimming analyzers

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions