Repository navigation
Closed
Labels
Milestone
Description
Rationale
Immo Landwerth (@terrajobst) has proposed a mechanism to improve obsoleting APIs by extending ObsoleteAttribute, affectionally known as Better Obsoletion. Recently, that proposed addition was merged into the framework and the compilers honor the new properties as of dotnet/roslyn#42518. In light of this, it seems like a good idea to gather a list of APIs that should be considered for Better Obsoletion, so there's a central place to discuss/review/suggest these.
Obsolete APIs
This list is by no means exhaustive, but it'll kickstart the discussion.
The three examples from the design doc:
SecureString- Obsolete the SecureString type #30612HttpWebRequest(and related) - Obsolete old HTTP APIs #33125- Non-generic collections - (no issue)
A quick search for 'obsolete' in dotnet/runtime revealed these:
Uri.EscapeUriString- [Uri] Uri.EscapeUriString should be deprecated #31387- This comment by @karelz mentions there's a few other bad APIs on
Uri, but doesn't specify which.
- This comment by @karelz mentions there's a few other bad APIs on
Assembly.CodeBase- Mark Assembly.CodeBase as obsolete #31127RuntimeHelpers.OffsetToStringData- API proposal: Obsolete RuntimeHelpers.OffsetToStringData #31406(Handled in Add spec for obsoletions in .NET 5 designs#139)Thread.Abort- Request Thread.Abort to be marked [Obsolete] #28664IAsyncResult- Deprecate IAsyncResult #27936HandleProcessCorruptedStateExceptionsAttribute- Consider marking HandleProcessCorruptedStateExceptionsAttribute as obsolete/hidden #31157BinaryFormatter- Remove BinaryFormatter from the shared framework in .NET 5 #29976StringDictionary- Mark StringDictionary as obsolete #889UTF-7 Encoding - Proposal: Obsolete UTF-7 encoding in the framework #32284(Handled in Obsolete Encoding.UTF7 property and UTF7Encoding ctors #37535)(Handled in Add spec for obsoletions in .NET 5 designs#139)PrincipalPermissionAttribute(and related) - Non-support of PrincipalPermissionAttribute #31279
Other APIs to be considered:
implicit operator DateTimeOffset(DateTime)- Feature proposal: remove implicit construction of DateTimeOffset from DateTime #32954UnmanagedType.AnsiBStr(and a few others) - UnmanagedType.AnsiBStr is marked as obsolete with no alternative given #31006- These values are already marked obsolete, but it would be an improvement to give them a dedicated diagnostic ID.
Reacted by John Tur, strangeman375, Eric Tuvesson, Clinton Ingram and Vyacheslav Napadovsky
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Kryptos-FR commentedon Mar 12, 2020
There was an issue I opened a while ago regarding
ArrayListin .Net Standard (dotnet/standard#296).Which leads me to the question: would that obsoletion also be applied to the standard, or only to .NET5?
Joe4evr commentedon Mar 13, 2020
@Kryptos-FR The idea of .NET Standard was to unify the API surface area across multiple implementations of the .NET runtime. With .NET 5 being the unification of those to a single runtime implementation, the purpose of .NET Standard loses its meaning in that new world.
As such, don't hold your breath on the Standard still evolving.
jeffhandley commentedon Jul 13, 2020
We created dotnet/designs#139, which includes a few APIs mentioned here.
slavanap commentedon Jul 18, 2020
Can I obsolete specific objects from another library (including .NET itself) in my project, if they aren't obsoleted in their source?
chucker commentedon Jul 18, 2020
You can write an analyzer. Consider forking https://github.com/dotnet/platform-compat
slavanap commentedon Jul 18, 2020
@chucker is it correct if I would ever want to restrict some API usages in my project, I would need to build custom analyzer for it which I would later use for code check?
Joe4evr commentedon Jul 18, 2020
@slavanap For code that you own, you can simply apply
[Obsolete]with your own value for the newDiagnosticIdproperty.slavanap commentedon Jul 18, 2020
What about the case when I want to restrict usage of implicit operator, code of which I do not own?
jeffhandley commentedon Jul 18, 2020
Note that we are working to fully productize the
platform-compatanalyzer, to get it integrated into the .NET SDK for .NET 5. It will use the new platform-specific support attributes and respect the newIsOSPlatformOrLaterandIsOSPlatformEarlierThanmethods.Here's the draft PR from @buyaa-n if you're curious; we expect the PR into dotnet/runtime will be created within the next couple weeks.
@slavanap Other than including an analyzer in your package as was suggested, there isn't a way to cast
[Obsolete]attributes onto APIs exposed from one of your dependencies (or the .NET Libraries).jeffhandley commentedon Jul 21, 2020
Ha -- my goodness, I got my wires crossed on the previous comment, @slavanap, and I referenced the wrong attributes that the Platform Compat Analyzer will be using. I've fixed the comment above to be accurate.
jeffhandley commentedon Aug 11, 2021
With the bulk of these issues now addressed, I'm going to close this issue. #46767 captured the obsoletions completed in .NET 6 and I filed #57207 to capture the remaining items from that list and this one for carrying forward into .NET 7.
Thanks for originally filing this, @Joe4evr--this was a big help to steer our efforts and shape our obsoletion work.