Skip to content

[AOT] Fix Blazor AOT warnings #45473

@JamesNK

Description

@JamesNK

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Hosting, HTTP, servers, middleware, routing, and auth were annotated for trimming in .NET 7. Projects with trimming are at https://github.com/dotnet/aspnetcore/blob/82daf67c4754ae5b1beac13d14c1b2e49b1351e8/eng/TrimmableProjects.props.

AOT adds new analysis warnings. I tested enabling AOT analysis for all trimmable projects and got 80ish warnings.

image

These warnings seem to fall into a bunch of categories:

  • Reflection with MakeGenericType and MakeGenericMethod. These methods can't be used with value types in AOT. Fortunately, most usages are with reference types, so they can be suppressed.
  • Code that has been made safe during trimming effort but is only suppressed for trim warnings. Need to be suppressed for AOT warnings.
  • Similar to the previous category, there is code identified as never safe (e.g. reflection-based minimal APIs). The public APIs need to be marked as unsafe. This is required so a warning is only raised if the public API is used.
  • Warnings from dependency injection (mostly hosting) and System.Text.Json. Some work with Microsoft.Extensions.DependenceInjection team will be required to develop a good solution for DI safety.
  • Middleware uses a lot of reflection. There is work to have source generation replace reflection here. @davidfowl might be working on this. Talk with him around middleware pipeline.

Describe the solution you'd like

Enable AOT analysis for all the projects in https://github.com/dotnet/aspnetcore/blob/82daf67c4754ae5b1beac13d14c1b2e49b1351e8/eng/TrimmableProjects.props. Most of these projects are in @adityamandaleeka space, but there are a couple of components projects for @mkArtakMSFT. Can place <EnableAOTAnalyzer>false</EnableAOTAnalyzer> to exclude some projects temporarily.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions