Skip to content

How to tell if a Type is "awaitable" in native AOT / trimmed apps #103258

Open
@eerhardt

Description

@eerhardt

In ASP.NET Core, we have some code that determines if a Type is "awaitable". See

https://github.com/dotnet/aspnetcore/blob/206b0aeca39d5eb12e55ce4e35ef4c8b9bc63c86/src/Shared/ObjectMethodExecutor/AwaitableInfo.cs#L46-L109

(Note that this code has invalid UnconditionalSuppressMessage attributes. These suppressions will be removed in a forth-coming PR.)

There are places in ASP.NET Core that need to do special operations for "awaitable" Types. For example, wrapping the custom awaitable in an ObjectMethodExecutorAwaitable.

However, in doing this, the code needs to do reflection on the Type in such a way that will break in trimmed apps. There doesn't appear to be a way to support custom awaitable Types at runtime. Instead, the only viable solution appears to be to use a source generator.

cc @MichalStrehovsky @agocke @davidfowl @BrennanConroy

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Reflectionneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions