Skip to content
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

Add obsolete attribute to DisablePrivateReflectionAttribute #49550

Merged
merged 15 commits into from
Mar 17, 2021
Merged

Add obsolete attribute to DisablePrivateReflectionAttribute #49550

merged 15 commits into from
Mar 17, 2021

Conversation

annchous
Copy link
Contributor

Close #43247

@annchous
Copy link
Contributor Author

annchous commented Mar 12, 2021

It seems to me that a more appropriate tag is area-System.Runtime.CompilerServices

@annchous
Copy link
Contributor Author

cc: @stephentoub @jkotas

@@ -3,6 +3,7 @@

namespace System.Runtime.CompilerServices
{
[Obsolete("DisablePrivateReflectionAttribute has no effect in .NET Core and .NET 5.0+ applications.")]
Copy link
Member

@stephentoub stephentoub Mar 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

Per #43247 (comment), this needs an ID set on it. That ID will need to be recorded in https://github.com/dotnet/runtime/blob/0c3cc15f90f0e3b81ce3199be1ac217564043635/src/libraries/Common/src/System/Obsoletions.cs. You can see other examples in that file and how they're used in call sites.

In addition, this is editing the src file, but the class in the reference assembly file https://github.com/dotnet/runtime/blob/79ae74f5ca5c8a6fe3a48935e85bd7374959c570/src/libraries/System.Runtime/ref/System.Runtime.cs will also need to have the attribute applied.

@@ -3,6 +3,7 @@

namespace System.Runtime.CompilerServices
{
[Obsolete(Obsoletions.EscapeUriStringMessage, DiagnosticId = Obsoletions.EscapeUriStringDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a new message and new diagnostic ID for this particular obsoletion added to that file, and then those new values used here. It shouldn't use the existing ones, which aren't relevant to this API.

@@ -9381,6 +9381,7 @@ public sealed partial class DependencyAttribute : System.Attribute
public string DependentAssembly { get { throw null; } }
public System.Runtime.CompilerServices.LoadHint LoadHint { get { throw null; } }
}
[System.ObsoleteAttribute("DisablePrivateReflectionAttribute has no effect in .NET Core and .NET 5.0+ applications.", DiagnosticId = "SYSLIB0013", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SYSLIB0013 is already taken. A new obsoletion ID is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mentioned in the commentary on this issue, so I decided that it was necessary to use it. Thanks for the explanation. Can I take SYSLIB0015 instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I did it right :)

@annchous
Copy link
Contributor Author

@stephentoub
Copy link
Member

should I contribute the new obsoletion ID here

Yes, please. Thanks.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@annchous
Copy link
Contributor Author

@stephentoub I've finished with docs. Thank you too.

@annchous
Copy link
Contributor Author

I see that some of the checks failed (exactly half). It is necessary to somehow mark in which places there should be no warnings that the attribute is now obsolete. How should this be done?

@@ -48,5 +48,8 @@ internal static class Obsoletions

internal const string WebRequestMessage = "Use HttpClient instead.";
internal const string WebRequestDiagId = "SYSLIB0014";

internal const string DisablePrivateReflectionAttributeMessage = "DisablePrivateReflectionAttribute has no effect in .NET Core and .NET 5.0+ applications.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This attribute still has effect in a few corner cases in CoreCLR. Search for DisablePrivateReflection under src\coreclr and delete everything found.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we may want to say .NET 6.0+ in the error message.

@annchous
Copy link
Contributor Author

annchous commented Mar 13, 2021

@jkotas I've finished with changes that you requested. But there is some trouble with building libs:

C:\runtime\artifacts\obj\netstandard\net6.0-Debug\netstandard.Forwards.cs(1524,67): error SYSLIB0015: "DisablePrivateReflectionAttribute" is obsolete: 
'DisablePrivateReflectionAttribute has no effect in .NET Core and .NET 6.0+ applications.' [C:\runtime\src\libraries\shims\generated\netstandard.csproj]

How can this be fixed?

@jkotas
Copy link
Member

jkotas commented Mar 13, 2021

@jkotas
Copy link
Member

jkotas commented Mar 13, 2021

How can this be fixed?

Try to add <NoWarn>$(NoWarn);SYSLIB0015</NoWarn> to src\libraries\shims\generated\netstandard.csproj .

@annchous
Copy link
Contributor Author

Try to add <NoWarn>$(NoWarn);SYSLIB0015</NoWarn> to src\libraries\shims\generated\netstandard.csproj .

Yes, I've tried that. This cleared the error from netstandard, but followed in turn by the same error from mscorelib (src\libraries\shims\generated\mscorlib.csproj). If you insert NoWarn in src\libraries\shims\generated\mscorlib.csproj, then the error occurs in System.Runtime.csproj.

@jkotas
Copy link
Member

jkotas commented Mar 13, 2021

@annchous
Copy link
Contributor Author

@jkotas I've tried to add <NoWarn>$(NoWarn);SYSLIB0015</NoWarn> to every project file I mentioned above. Now it builds successfully, but is it ok to do like that?

@jkotas
Copy link
Member

jkotas commented Mar 13, 2021

I think it is ok.

@annchous
Copy link
Contributor Author

Ok, then try this central place instead: https://github.com/dotnet/runtime/blob/main/src/libraries/Directory.Build.targets#L20

@jkotas That works nice and looks better than adding NoWarn to every project file. I will commit this change. Thank you!

@annchous
Copy link
Contributor Author

@jkotas I think I have definitely finished working on this now. The checks are going well. Anything else?

@@ -48,5 +48,8 @@ internal static class Obsoletions

internal const string WebRequestMessage = "Use HttpClient instead.";
internal const string WebRequestDiagId = "SYSLIB0014";

internal const string DisablePrivateReflectionAttributeMessage = "DisablePrivateReflectionAttribute has no effect in .NET Core and .NET 6.0+ applications.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
internal const string DisablePrivateReflectionAttributeMessage = "DisablePrivateReflectionAttribute has no effect in .NET Core and .NET 6.0+ applications.";
internal const string DisablePrivateReflectionAttributeMessage = "DisablePrivateReflectionAttribute has no effect in .NET 6.0+ applications.";

@@ -9381,6 +9381,7 @@ public sealed partial class DependencyAttribute : System.Attribute
public string DependentAssembly { get { throw null; } }
public System.Runtime.CompilerServices.LoadHint LoadHint { get { throw null; } }
}
[System.ObsoleteAttribute("DisablePrivateReflectionAttribute has no effect in .NET Core and .NET 6.0+ applications.", DiagnosticId = "SYSLIB0015", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[System.ObsoleteAttribute("DisablePrivateReflectionAttribute has no effect in .NET Core and .NET 6.0+ applications.", DiagnosticId = "SYSLIB0015", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
[System.ObsoleteAttribute("DisablePrivateReflectionAttribute has no effect in .NET 6.0+ applications.", DiagnosticId = "SYSLIB0015", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@stephentoub stephentoub merged commit 0b7bcf0 into dotnet:main Mar 17, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Apr 16, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API proposal: obsolete DisablePrivateReflectionAttribute
4 participants