Skip to content

Add polyfills for .NET 10 attributes.#131

Merged
Sergio0694 merged 6 commits into
Sergio0694:mainfrom
teo-tsirpanis:net10
May 25, 2026
Merged

Add polyfills for .NET 10 attributes.#131
Sergio0694 merged 6 commits into
Sergio0694:mainfrom
teo-tsirpanis:net10

Conversation

@teo-tsirpanis

@teo-tsirpanis teo-tsirpanis commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

Note

Depends on #127.

API breakdown (for new features)

Polyfills for the following attributes were added:

  • [CompilerLoweringPreserve]
    • Also applied to the polyfill for DynamicallyAccessedMembersAttribute, matching upstream.
  • [ExtensionMarker]
  • The DynamicDependencyAttrribute.Condition property in the polyfill was obsoleted and hidden, matching upstream.

Polyfills for the following runtime-supported attributes were added:

  • [UnsafeAccessorType]

Additional context (optional)

The list of attributes was populated by searching for the regex : .+Attribute in files matching release-notes/10.0/api-diff/Microsoft.NETCore.App in the branch of dotnet/core#10147, and excluding the attributes in OOB packages.

.NET 10 added the following properties to existing attributes that we polyfill:

namespace System.Diagnostics.CodeAnalysis
{
    public sealed class ExperimentalAttribute : System.Attribute
    {
+       public string? Message { get; set; }
    }
    public sealed class RequiresDynamicCodeAttribute : System.Attribute
    {
+       public bool ExcludeStatics { get; set; }
    }
    public sealed class RequiresUnreferencedCodeAttribute : System.Attribute
    {
+       public bool ExcludeStatics { get; set; }
    }
}

Because it would lead to an inconsistent experience, where the polyfills will be added when targeting say .NET Standard, but not a .NET version earlier than 10, these changes are not polyfilled at this moment.

Also, the following runtime-supported attributes were not polyfilled:

  • TypeMapAssemblyTargetAttribute<TTypeGroup>, TypeMapAssociationAttribute<TTypeGroup>, and TypeMapAttribute<TTypeGroup>, because they are generic and would cause issues on downlevel runtimes.
  • MetadataUpdateDeletedAttribute, because it is emitted by Hot Reload, and applying it manually is not allowed.

@teo-tsirpanis

Copy link
Copy Markdown
Contributor Author

PR description updated for .NET 10 RTM's release; no new useful attributes were added since. This is ready for review.

@teo-tsirpanis teo-tsirpanis marked this pull request as ready for review November 22, 2025 19:06
@Sergio0694 Sergio0694 deleted the branch Sergio0694:main May 25, 2026 17:54
@Sergio0694 Sergio0694 closed this May 25, 2026
@Sergio0694 Sergio0694 reopened this May 25, 2026
@teo-tsirpanis teo-tsirpanis changed the base branch from dev/embedded-types to main May 25, 2026 18:40
@Sergio0694 Sergio0694 force-pushed the net10 branch 2 times, most recently from addb7b5 to 2372b4c Compare May 25, 2026 18:43
Introduce a CompilerLoweringPreserve-marked TestFlowingAttribute and an ExtensionContainer to exercise the new extension/ExtensionMarker language feature in tests. Also add a new extern ref accessor GetAnonymousField to RuntimeSupport with UnsafeAccessorType "Foo, PolySharp.ExternalTypes" to support tests for unsafe field access on external/anonymous types.
Rename embedded resource source file from System.Diagnostics.CodeAnalysis.UnsafeAccessorTypeAttribute.cs to System.Runtime.CompilerServices.UnsafeAccessorTypeAttribute.cs to reflect the correct namespace. File contents are unchanged (100% similarity).

@Sergio0694 Sergio0694 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks great, thank you!! 😄

@Sergio0694 Sergio0694 merged commit 4d06ed1 into Sergio0694:main May 25, 2026
5 checks passed
@teo-tsirpanis teo-tsirpanis deleted the net10 branch May 25, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants