Skip to content

No platform compatability analyzer warnings in Razor @code sections #7250

Open
@lambdageek

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

  1. Install a .NET 7 preview SDK or .NET 6
  2. dotnet new blazorwasm
  3. edit Counter.razor and change IncrementCount to the following:
      private void IncrementCount() {
          new Thread(() => { Console.WriteLine("hello"); }).Start();
          currentCount++;
      }
  4. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions