Skip to content

.NET 6 Bindings: "Deprecated since" with Obsolete; UnsupportedOSPlatform #6349

@bddckr

Description

@bddckr

Issue

I have a native API I'd like to generate bindings for. This API is available in API level A, was deprecated in B and removed in C. (With A < B < C.) What I'm thus looking for is a way to mark the API to be

  1. introduced in API level A and to not be available on earlier API levels.
  2. deprecated in API level B.
  3. not available starting with API level C.

It looks like xamarin/java.interop/#773 added SupportedOSPlatform, taking care of (1). I tested this with api-since="27" in my Metadata.xml and it works without issues 🎉

But for APIs that are deprecated only starting in a specific API level, it looks like the bindings generation process is not able to add anything to the generated output to tell the bindings consumer about the API level the API is deprecated in.

Here's an example:
DevicePolicyManager.ClearDeviceOwnerApp was introduced in API level 21 and deprecated in 26. Currently, the Xamarin.Android bindings ship with this (decompiled from the ref dll):

[Obsolete("deprecated")]
[Register("clearDeviceOwnerApp", "(Ljava/lang/String;)V", "GetClearDeviceOwnerApp_Ljava_lang_String_Handler")]
public virtual void ClearDeviceOwnerApp(string packageName)
{
    throw null;
}

Note that it just marks it as deprecated, with no way to figure out that it's actually available just fine if you target any version in [21, 26). So it seems like (2) cannot be handled currently. I'm not aware of anything in the .NET tooling to allow this, but I figured it's worth asking if there is a way.

For (3) I wonder if it's possible for the generator to add UnsupportedOSPlatform on a generated symbol. Just like support for SupportedOSPlatform was added already.

Version Information

VS 2022 (Version 17.0.0 Preview 4.1)
.NET 6 (6.0.100-rc.1.21463.6)

Metadata

Metadata

Assignees

Labels

Area: BindingsIssues in Java Library Binding projects.needs-triageIssues that need to be assigned.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions