Skip to content

[Mono.Android] Treat obsolete attributes as errors - #13124

Closed
simonrozsival wants to merge 3 commits into
release/11.0.1xxfrom
simonrozsival-obsolete-api-errors-11-0-1xx
Closed

simonrozsival wants to merge 3 commits into
release/11.0.1xxfrom
simonrozsival-obsolete-api-errors-11-0-1xx

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

This separate release-branch follow-up responds to Jonathan Peppers' review
request in #13109. It makes
Android.Runtime.PreserveAttribute, Android.LinkerSafeAttribute, and
Java.Interop.DoNotPackageAttribute compiler errors without changing their
existing obsolete messages. The linker test now uses
DynamicDependencyAttribute, and the expected metadata differences are
recorded in the API compatibility baseline.

Validation

  • dotnet build src/Mono.Android/Mono.Android.csproj --no-restore -p:JavaCPath=/Users/simon/Library/Java/JavaVirtualMachines/jdk-23.0.2+7/Contents/Home/bin/javac -p:JarPath=/Users/simon/Library/Java/JavaVirtualMachines/jdk-23.0.2+7/Contents/Home/bin/jar -v:minimal — passed (28 warnings, 0 errors).
  • dotnet build tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj --no-restore -p:JavaCPath=/Users/simon/Library/Java/JavaVirtualMachines/jdk-23.0.2+7/Contents/Home/bin/javac -p:JarPath=/Users/simon/Library/Java/JavaVirtualMachines/jdk-23.0.2+7/Contents/Home/bin/jar -v:quiet — passed (95 warnings, 0 errors). This builds the test assembly; tests were not executed.

This release follow-up marks Android.Runtime.PreserveAttribute,
Android.LinkerSafeAttribute, and Java.Interop.DoNotPackageAttribute as
compiler errors before their planned removal.  Keep the existing messages,
migrate the linker test to DynamicDependencyAttribute, and record the
expected API compatibility differences.

Follow up to #13109.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 15:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Existing build tests still compile PreserveAttribute and DoNotPackageAttribute usages and will now fail with CS0619.

2 open findings
What changed in this PR

Makes three obsolete Mono.Android attributes produce compiler errors and updates linker/API compatibility metadata.

Changes:

  • Marks obsolete attributes with error: true.
  • Replaces linker test preservation with DynamicDependency.
  • Records API compatibility differences.
File Description
Android.Runtime/​PreserveAttribute.cs Makes usage a compiler error.
Android/​LinkerSafeAttribute.cs Makes usage a compiler error.
Java.Interop/​DoNotPackageAttribute.cs Makes usage a compiler error.
System.Linq/​LinqExpressionTest.cs Replaces Preserve with DynamicDependency.
acceptable-breakages-vReference-net11.0.txt Records obsolete metadata changes.

🧠 Review effort: Balanced

namespace Android.Runtime {

[Obsolete ("Please use [System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute]")]
[Obsolete ("Please use [System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute]", error: true)]
AllowMultiple=true,
Inherited=false)]
[Obsolete ("This attribute is deprecated and will be removed in a future release. Use the @(AndroidExternalJavaLibrary) MSBuild item group instead.")]
[Obsolete ("This attribute is deprecated and will be removed in a future release. Use the @(AndroidExternalJavaLibrary) MSBuild item group instead.", error: true)]
simonrozsival and others added 2 commits October 13, 2026 17:19
Move the DynamicDependencyAttribute onto a ModuleInitializer method so the
dependency is rooted independently of the target test method.  This keeps
LinqExpressionTest and its members available for linker-based discovery,
without referencing PreserveAttribute after it becomes an error.

Co-authored-by: Copilot App <[email protected]>
Remove the preservation hint from LinqExpressionTest after verifying that
Release linking still discovers and runs it.  The complete on-device
runtime suite passes without PreserveAttribute or DynamicDependencyAttribute.

Co-authored-by: Copilot App <[email protected]>
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