Open lambdageek opened 2 years ago
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 .g.cs
or add /// <Autogenerated>
to the top of the file. That will cause the regular analyzer heuristics to kick in and treat it as generated code, much the same as if a tool had added it outside the compilation pipeline.
@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 @code
looks like user-written code to me and shouldn't be marked as generated.
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