No platform compatability analyzer warnings in Razor @code sections #7250
Open
Description
Is there an existing issue for this?
- I have searched the existing issues
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:
warning CA1416: This call site is reachable on: 'browser'. 'Thread.Start()' is unsupported on: 'browser'. [/Users/alklig/work/multi-blazy/multi-blazy.csproj]
Steps To Reproduce
- Install a .NET 7 preview SDK or .NET 6
dotnet new blazorwasm
- edit
Counter.razor
and changeIncrementCount
to the following:private void IncrementCount() { new Thread(() => { Console.WriteLine("hello"); }).Start(); currentCount++; }
dotnet build
Expected result: CA1416 warning about use of Thread.Start()
.
Actual result: no warning.
Now add new Thread(() => { Console.WriteLine ("hi"); }).Start()
somewhere in Program.cs
and rebuild. Note that a CA1416 is generated:
/Users/alklig/work/multi-blazy/Program.cs(12,1): warning CA1416: This call site is reachable on all platforms. 'Thread.Start()' is unsupported on: 'browser'. [/Users/alklig/work/multi-blazy/multi-blazy.csproj]
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
Activity