Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 6: Trimmer does not follow async flows #2366

Closed
yaakov-h opened this issue Nov 14, 2021 · 3 comments
Closed

.NET 6: Trimmer does not follow async flows #2366

yaakov-h opened this issue Nov 14, 2021 · 3 comments

Comments

@yaakov-h
Copy link
Member

This code:

using System.Diagnostics.CodeAnalysis;

namespace Trimmable
{
    public class DoSomething
    {
        public static async Task WithAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>()
        {
            await Task.Delay(100);
            With<T>();
        }

        public static void With<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>()
        {
        }
    }
}

looks like it should be safe, as both methods share the same annotation and one simply calls the other, yet it yields this warning:

Trim analysis warning IL2091: Trimmable.DoSomething.d__0.MoveNext(): 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in 'Trimmable.DoSomething.With()'. The generic parameter 'T' of 'Trimmable.DoSomething.d__0' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

I am assuming the linker got lost in the compiler-generated async state machine code.

@marek-safar
Copy link
Contributor

/cc @sbomer @vitek-karas

@vitek-karas
Copy link
Member

This is a known limitation in .NET 6. We implemented only handling of RequiresUnreferencedCodeAttribute and warning suppression for async state machines. The data flow for annotations (DynamicallyAccessedMembersAttribute and friends) was not implemented in .NET 6.

Master issue: #2001

Document describing the desired behavior and some solutions is here: https://github.com/dotnet/linker/blob/main/docs/design/compiler-generated-code-handling.md

@sbomer sbomer added this to AppModel Apr 25, 2024
@sbomer
Copy link
Member

sbomer commented Jun 24, 2024

Closing because we don't plan to fix this for the .NET 6 illink. Please use a later version of .NET to get the fixes from #2001.

@sbomer sbomer closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants