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

Default Blazor WASM project should not produce trim warnings #44845

Open
1 task done
yugabe opened this issue Nov 2, 2022 · 13 comments
Open
1 task done

Default Blazor WASM project should not produce trim warnings #44845

yugabe opened this issue Nov 2, 2022 · 13 comments
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-trimming Pillar: Technical Debt Priority:1 Work that is critical for the release, but we could probably ship without

Comments

@yugabe
Copy link

yugabe commented Nov 2, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The default project templates for Blazor WASM apps use trimming, but trimming warnings are suppressed by default. Enabling trim warnings shows there are a number of issues with how the API is annotated.

Unfortunately, there isn't guidance available on how to actually (correctly) fix the issues pointed to by these warnings.

Assuming that the application works correctly when trimmed in all cases, it means one or more of:

  • the underlying APIs are incorrectly annotated,
  • the underlying APIs or app are not suitable for trimming,
  • the app produced by the default app template might break at runtime,
  • the user is expected to fix the warnings, which are disabled by default, and there isn't sufficient guidance for them to do so (using the guidance referenced by the warnings the user won't be able to solve the issues correctly),
  • warnings might be invalid.

Expected Behavior

The default project templates (at least) should be able to be published without trim warnings or there should be guidance on how to fix the warnings and point out in the documentation that this is the case (the default template isn't suitable for trimming).

Steps To Reproduce

dotnet new blazorwasm
dotnet publish -p:SuppressTrimAnalysisWarnings=false

Exceptions (if any)

All of the following warnings are issued.

ILLink : Trim analysis warning IL2111: BlazorTrimTest.App.<>c.<BuildRenderTree>b__0_1(RenderTreeBuilder): Method 'Microsoft.AspNetCore.Components.LayoutView.WrapInLayout(Type, RenderFragment)' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements o
f the method. [~\BlazorTrimTest\BlazorTrimTest.csproj]

ILLink : Trim analysis warning IL2111: BlazorTrimTest.App.<>c.<BuildRenderTree>b__0_1(RenderTreeBuilder): Method 'Microsoft.AspNetCore.Components.LayoutView.Layout.set' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method. [~\BlazorTrimTest\BlazorTrimTest.csproj]

ILLink : Trim analysis warning IL2118: BlazorTrimTest.App.<>c.<BuildRenderTree>b__0_1(RenderTreeBuilder): Compiler-generated member 'Microsoft.AspNetCore.Components.LayoutView.<>c__DisplayClass13_0.<WrapInLayout>g__Render|0(RenderTreeBuilder)' is accessed via reflection. Trimmer can't guarantee availability of the requirements of the member. [~\BlazorTrimTest\BlazorTrimTest.csproj]

ILLink : Trim analysis warning IL2111: BlazorTrimTest.App.<>c.<BuildRenderTree>b__0_1(RenderTreeBuilder): Method 'Microsoft.AspNetCore.Components.LayoutView.Layout.set' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method. [~\BlazorTrimTest\BlazorTrimTest.csproj]

ILLink : Trim analysis warning IL2110: BlazorTrimTest.App.<>c.<BuildRenderTree>b__0_1(RenderTreeBuilder): Field 'Microsoft.AspNetCore.Components.LayoutView.<Layout>k__BackingField' with 'DynamicallyAccessedMembersAttribute' is accessed via reflection. Trimmer can't guarantee availability of the requirements of the field. [~\BlazorTrimTest\BlazorTrimTest.csproj]

~\BlazorTrimTest\Pages\FetchData.razor(44,9): Trim analysis warning IL2026: BlazorTrimTest.Pages.FetchData.<OnInitializedAsync>d__2.MoveNext(): Using member 'System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsync<TValue>(HttpClient, String, CancellationToken)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved. [~\BlazorTrimTest\BlazorTrimTest.csproj]

ILLink : Trim analysis warning IL2118: BlazorTrimTest.App.BuildRenderTree(RenderTreeBuilder): Compiler-generated member 'Microsoft.AspNetCore.Components.Routing.Router.<RunOnNavigateAsync>d__61.path' is accessed via reflection. Trimmer can't guarantee availability of the requirements of the member. ~\BlazorTrimTest\BlazorTrimTest.csproj]

~...\.nuget\packages\microsoft.aspnetcore.components\7.0.0-rc.2.22476.2\lib\net7.0\Microsoft.AspNetCore.Components.dll : warning IL2104: Assembly 'Microsoft.AspNetCore.Components' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [~\BlazorTrimTest\BlazorTrimTest.csproj]

~...\.nuget\packages\microsoft.jsinterop\7.0.0-rc.2.22476.2\lib\net7.0\Microsoft.JSInterop.dll : warning IL2104: Assembly 'Microsoft.JSInterop' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [~\BlazorTrimTest\BlazorTrimTest.csproj]

.NET Version

7.0.100-rc.2.22477.23

Anything else?

Marginally related: #39839

@blowdart blowdart added the feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly label Nov 2, 2022
@TanayParikh TanayParikh added the area-blazor Includes: Blazor, Razor Components label Nov 2, 2022
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Nov 3, 2022
@mkArtakMSFT mkArtakMSFT added task bug This issue describes a behavior which is not expected - a bug. triaged and removed task labels Nov 3, 2022
@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, .NET 8 Planning Nov 3, 2022
@ghost
Copy link

ghost commented Nov 3, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost
Copy link

ghost commented Nov 3, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@Blackclaws
Copy link

Just ran into this issue. We wanted to find issues with trimming because the wasm app wasn't keeping some classes. The deluge of warnings is really irritating to work with.

@hjrb
Copy link

hjrb commented Dec 8, 2022

I agree. E.g. a simple HttpClient.GetFromJsonAsync triggers the warning
Severity Code Description Project File Line Suppression State
Warning IL2026 Using member 'System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsync(HttpClient, String, CancellationToken)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved. VSSApp.Client C:\Users\ret2fe\Projects\repos\hjrb\VSSApp\Client\Pages\AdminPage.razor.cs 49 N/A

That is all around.
Also for entity framework core: DbContext(DbContextOptions<...> options) - same!
This renders trimming kind of useless.

@Blackclaws
Copy link

I agree. E.g. a simple HttpClient.GetFromJsonAsync triggers the warning Severity Code Description Project File Line Suppression State Warning IL2026 Using member 'System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsync(HttpClient, String, CancellationToken)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved. VSSApp.Client C:\Users\ret2fe\Projects\repos\hjrb\VSSApp\Client\Pages\AdminPage.razor.cs 49 N/A

That is actually valuable feedback that makes sense as a warning. Because there is actually a way to use this functionality that preserves the correct type info as the warning states.

The issue really is with warnings that come from the generated code in Razor files I find.

@hjrb
Copy link

hjrb commented Dec 8, 2022

That is actually valuable feedback that makes sense as a warning. Because there is actually a way to use this functionality that preserves the correct type info as the warning states.
I don't know how. Do you?

@yugabe
Copy link
Author

yugabe commented Dec 8, 2022

@hjrb, it is covered in the docs here.

This issue here is not about warnings about trimming in general - they are unarguably useful. It's about how there are already warnings in the default project without adding any custom code to it.

@hjrb
Copy link

hjrb commented Dec 8, 2022

Thanks for the link. But see: even as part of the Blazor WASM template there is such a call HttpClient.GetFromJsonAsync to get the Weather Data.

@yugabe
Copy link
Author

yugabe commented Dec 8, 2022

Ah, I see. In that case sure, this is exactly what the issue is 😅
In fact, upon taking another look, I mention this exact one in the issue OP too.
The best case study is right here. The warnings are not straightforward to fix (usually), so the template itself should include them by default as is advised by the warning.

@hjrb
Copy link

hjrb commented Dec 8, 2022

The warnings are not straightforward to fix (usually), so the template itself should include them by default as is advised by the warning.
Exactly.

@hjrb
Copy link

hjrb commented Dec 8, 2022

I gave it a try with the method for JSON Serializer Code generation. That works OK as long as you use only trivial types. But as soon as you use nested types like IEnumerable it doesn't work right away. I didn't want to spend the effort to figure out how to make it work. That should be included in the templates - as requested. With a reasonable, non trivial example.

@ghost
Copy link

ghost commented Oct 6, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@mkArtakMSFT mkArtakMSFT added this to the .NET 9 Planning milestone Dec 13, 2023
@ghost
Copy link

ghost commented Dec 13, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@mkArtakMSFT mkArtakMSFT added the Priority:1 Work that is critical for the release, but we could probably ship without label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-trimming Pillar: Technical Debt Priority:1 Work that is critical for the release, but we could probably ship without
Projects
None yet
Development

No branches or pull requests

7 participants
@blowdart @Blackclaws @yugabe @TanayParikh @hjrb @mkArtakMSFT and others