Skip to content

Obsolete PreserveAttribute #10734

Open
Open

Description

@marek-safar

The attribute is not needed in .NET6 and can interfere with official .NET linker attributes. The linker is able to recognize and mark reflection patterns automatically and for custom scenarios better attribute is supported https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.dynamicdependencyattribute. The assembly-level attribute handling is not needed either as that's the default .net6 behavior.

We'll need to update the generator to not generate the Preserve attribute first: #19524

Current plan:

  • .NET 12: remove all our own [Preserve] usages, and obsolete the attribute (show a warning when the attribute is used - [Obsolete ("...")])
  • .NET 13: show an error when the attribute is used, but existing binaries still work ([Obsolete ("...", IsError: true)]), show a build-time warning if such binaries are found ("won't work in future releases")
  • .NET 14: remove support for binaries with the attribute, keep showing a warning if such binaries are found (but change the message to "is ignored, nothing is preserved")

Activity

  1. added
    dotnet
    dotnet-pri3
    iOS
    macOS
    on Feb 26, 2021
  2. added this to the .NET 6 milestone on Feb 26, 2021
  3. modified the milestones: .NET 6, .NET 7 on Dec 10, 2021
  4. removed
    dotnet-pri3
    on Aug 26, 2022
  5. modified the milestones: .NET 7, .NET 8 on Aug 26, 2022
  6. modified the milestones: .NET 8, .NET 9 on Sep 12, 2023
  7. moved this to Technical Debt in .NET 9on Aug 27, 2024
  8. modified the milestones: .NET 9, .NET 10 on Sep 27, 2024
  9. modified the milestones: .NET 10, .NET 11 on Oct 22, 2025
  10. rolfbjarne commented on Jul 9, 2026

    @rolfbjarne
    Member

    This will be easier once we've removed the custom trimmer steps, so let's wait until then.

  11. modified the milestones: .NET 11, .NET 12 on Jul 9, 2026
  12. added theissue type on Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnetiOSmacOS

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions