dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.12k stars 4.04k forks source link

[.NET 10] certain `[Obsolete]` warnings are not reported #76226

Open jonathanpeppers opened 3 hours ago

jonathanpeppers commented 3 hours ago

Version Used: .NET SDK 10.0.100-alpha.1.24573.1

We noticed this from Maestro/codeflow here:

Steps to Reproduce:

  1. Call AppDomain.CreateDomain("test") in .NET 10
  2. Note that you don't get a SYSLIB0024 warning

Repro: testroslyn.zip

Note that this seems to work fine using net9.0 and a .NET 9 SDK.

Diagnostic Id:

SYSLIB0024: 'AppDomain.CreateDomain(string)' is obsolete: 'Creating and unloading AppDomains is not supported and throws an exception.'

Expected Behavior:

I get a SYSLIB0024 warning.

Actual Behavior:

I get no SYSLIB0024 warning.

Other info:

Note that if I open packs\Microsoft.NETCore.App.Ref\10.0.0-alpha.1.24570.9\ref\net10.0\System.Runtime.dll, it looks correct:

Image

The warning also seems to work fine if I declare an [Obsolete] method within the C# file.

CyrusNajmabadi commented 3 hours ago

I don't know what SYSLIB is. But is isn't roslyn :)

jonathanpeppers commented 3 hours ago

@CyrusNajmabadi this is if you have [Obsolete(DiagnosticId=" and put SYSLIB0024. Maybe it is any [Obsolete] in a reference assembly?

jonathanpeppers commented 3 hours ago

Ok, this works fine, I get a warning if I call it:

[Obsolete]
public void Test()
{
}

This doesn't produce a warning at all:

[Obsolete("whoopsies", DiagnosticId = "SYSLIB0024")]
public void Test()
{
}