-
Notifications
You must be signed in to change notification settings - Fork 198
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
No platform compatability analyzer warnings in Razor @code sections #7250
Comments
Related to dotnet/roslyn#39758 |
This is also relevant to MAUI Blazor projects if a Razor component calls a platform-specific API that is not available on a particular platform. |
This is also very likely problematic for trimming warning analyzer /cc @agocke |
Unless there's something specific to this analyzer, this sounds like a Roslyn bug. It might be marked as generated code, which will silence analyzer warnings by default, but in this case I think it should probably classify as user code. cc @chsienki |
By default generator created code is marked as user code. However, the generator author can choose to give a hint name ending in |
@chsienki This bug is that warnings don't appear in razor code sections, though. Are either of those things added to razor compiled files? |
Got it, so then this looks like a Razor bug to me. If there's scaffolding code for Razor, that might be considered generated, but the stuff in |
Is there an existing issue for this?
Describe the bug
C# code in .razor files (in
@code
sections or elsewhere) should be analyzed by the platform compatibility analyzer in order to spot uses of APIs that are unsupported on the browser.Currently, in a blazorwasm project, only .cs files (which may be partial classes for Razor components) are analyzed and the CA1416 warnings are produced.
Expected Behavior
CA1416 warnings are produced for
@code
sections in .razor files:Steps To Reproduce
dotnet new blazorwasm
Counter.razor
and changeIncrementCount
to the following:dotnet build
Expected result: CA1416 warning about use of
Thread.Start()
.Actual result: no warning.
Now add
new Thread(() => { Console.WriteLine ("hi"); }).Start()
somewhere inProgram.cs
and rebuild. Note that a CA1416 is generated:Exceptions (if any)
No response
.NET Version
7.0.100-preview.2.22153.17
Anything else?
Also tested with .NET 6.0.x, same behavior
The text was updated successfully, but these errors were encountered: