question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[AOT] Fix Blazor AOT warnings

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
Nick-Stantoncommented, Dec 8, 2022

Warnings from dependency injection (mostly hosting) and System.Text.Json.

Web UI’s biggest pain point here is our JSON serialization and deserialization. To become more AOT-friendly, we need to do some work implementing System.Text.Json source generation into these scenarios. Getting some added performance improvements isn’t too bad of a side effect either!

Reflection with MakeGenericType and MakeGenericMethod. These methods can’t be used with value types in AOT.

Web UI has a small handful of these. I agree with @eerhardt’s point of adding some insurance, but otherwise they all looked suppressible.

There were a couple warnings related to DI and following the completion of dotnet/runtime#79286 we should follow up and make sure that they are resolved. I have tracked the projects that we need to change below.

CC @mkArtakMSFT

Projects for Web UI to resolve

Both JSON and Reflection

  • Microsoft.AspNetCore.Components

JSON

  • Microsoft.AspNetCore.Components.Web
  • Microsoft.AspNetCore.Components.WebAssembly
  • Microsoft.AspNetCore.Components.WebAssembly.Authentication
  • Microsoft.JSInterop

Reflection

  • Microsoft.AspNetCore.Routing
  • Microsoft.AspNetCore.Routing.Abstractions
2reactions
JamesNKcommented, Jan 4, 2023

I enabled AOT analysis for all server-focused trimmed projects in https://github.com/dotnet/aspnetcore/pull/45604

Warnings were addressed for ASP.NET Core server-focused projects (hosting, servers, middleware, etc). AOT analysis was disabled for Blazor projects. It should be re-enabled for Blazor projects when looking at this issue.

Disabled AOT analysis projects:

  • Microsoft.AspNetCore.Components
  • Microsoft.AspNetCore.Components.Web
  • Microsoft.JSInterop.WebAssembly
  • Microsoft.AspNetCore.Components.WebAssembly.Authentication
  • Microsoft.AspNetCore.Components.WebAssembly
Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core support for native AOT
When building the app, review and correct AOT warnings. An app that issues AOT warnings during publishing is not guaranteed to work ...
Read more >
Introduction to AOT warnings - .NET
Ideally, all applications that use native AOT should have no AOT warnings. If there are any AOT warnings, ensure there are no behavior...
Read more >
Blazor Gets Faster (Even Without AOT)
Lack of native AOT compilation in .NET Core is a sore spot for Microsoft, which recently published results of a survey indicating this...
Read more >
ASP.NET Gets Blazor WebAssembly AoT, Hot Reload, . ...
ASP.NET Gets Blazor WebAssembly AoT, Hot Reload, .NET MAUI Blazor Apps · You must run with the debugger attached to apply changes ·...
Read more >
How can I avoid AOT build error during publish ...
During development, this is not a problem, but a publish build with enabled AOT compilation fails. C:\Program Files\dotnet\packs\Microsoft.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found