You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Obsolete attribute used instead of ObsoletedOSPlatform attribute #7558
The old (now deprecated) GetPackageInfo method still emits this warning, even though OperatingSystem.IsAndroidVersionAtLeast is used: Warning CS0618 'PackageManager.GetPackageInfo(string, PackageInfoFlags)' is obsolete: 'deprecated'
This is because of this attribute: [System.Obsolete("deprecated")]
I think this attribute should be used instead: [ObsoletedOSPlatform("android30.0")]
I am using net7.0-android33.0 but still see the warning.
As I mentioned, some methods are annotated with ObsoletedOSPlatform while others aren't (they are annotated with System.Obsolete).
I basically right-click on the method (GetPackageInfo) in VS22 and select "Go to Definition". It shows me this:
When I do the same for other methods (GetInstallerPackageName), I see this:
Some of them were deprecated before our minimum API level (21), so they are just marked with the regular [Obsolete] since they are deprecated in all of our versions:
removePackageFromPreferred (String packageName) - deprecated in API-15
addPackageToPreferred (String packageName) - deprecated in API-15
addPreferredActivity (IntentFilter filter, int match, ComponentName[] set, ComponentName activity) deprecated in API-15
The others were obsoleted in API-33, so they should have the new attribute. Maybe there is something messed up because we have converted the int flags to enumerations. I will investigate.
But there appears to be no overload for (int flags) in the Xamarin.Android references.
This appears to be a case of us making an unfortunate name choice a long time ago.
The original methods from Google are:
public abstract PackageInfo GetPackageInfo(VersionedPackage versionedPackage, int flags)
public abstract PackageInfo GetPackageInfo(string packageName, int flags)
We want our APIs to be a little easier to use, so we converted the int flags parameter to an enum called PackageInfoFlags, so they now look like this:
public abstract PackageInfo GetPackageInfo(VersionedPackage versionedPackage, [GeneratedEnum] PackageInfoFlags flags)
public abstract PackageInfo GetPackageInfo(string packageName, [GeneratedEnum] PackageInfoFlags flags)
In API-33, it looks like Google has done the same thing we did and introduced new overloads that take an "enum-like" Java type:
public virtual PackageInfo GetPackageInfo(VersionedPackage versionedPackage, PackageManager.PackageInfoFlags flags)
public virtual PackageInfo GetPackageInfo(string packageName, PackageManager.PackageInfoFlags flags)
Note that instead of our enum PackageInfoFlags these use a Java class PackageManager.PackageInfoFlags which has the same name as our enum but is a different type.
Thus you have to look closer to see that methods that take the enum PackageInfoFlags (the int flags Java methods) are the ones that are deprecated, and the new methods that take the Java type PackageManager.PackageInfoFlags are not deprecated.
This causes a compile error in our Xamarin.Forms apps on Azure DevOps windows-2022 images.
[Obsolete] does not produce an error, it produces a warning. You likely have some form of <TreatWarningsAsErrors> or <WarningsAsErrors> in your project file. You will need to suppress the warning using the regular C# mechanisms so your project does not treat it as an error.
[Obsolete] does not produce an error, it produces a warning. You likely have some form of <TreatWarningsAsErrors> or <WarningsAsErrors> in your project file. You will need to suppress the warning using the regular C# mechanisms so your project does not treat it as an error.
We don't. We actually use [Obsolete] ourselves, which generates warning CS0618 without any errors. This specific one gets converted to Error CS0618: 'PackageManager.GetPackageInfo(string, PackageInfoFlags)' is obsolete: 'deprecated' and I don't know why.
We're going to suppress it in code with #pragma, but ultimately we want to be able to call the appropriate version of GetPackageInfo since we target API 33 but support down to 23, and don't want to have to upgrade to NET8 to do that...
Activity
jpobst commentedon Nov 16, 2022
[ObsoletedOSPlatform]was added in .NET 7, so if usingnet7.0-androidthis should be working. 😁Implemented in #7234
tipa commentedon Nov 16, 2022
I am using

net7.0-android33.0but still see the warning.As I mentioned, some methods are annotated with
ObsoletedOSPlatformwhile others aren't (they are annotated withSystem.Obsolete).I basically right-click on the method (
GetPackageInfo) in VS22 and select "Go to Definition". It shows me this:When I do the same for other methods (

GetInstallerPackageName), I see this:The file appears to be this:

jpobst commentedon Nov 16, 2022
Some of them were deprecated before our minimum API level (21), so they are just marked with the regular
[Obsolete]since they are deprecated in all of our versions:removePackageFromPreferred (String packageName)- deprecated in API-15addPackageToPreferred (String packageName)- deprecated in API-15addPreferredActivity (IntentFilter filter, int match, ComponentName[] set, ComponentName activity)deprecated in API-15The others were obsoleted in API-33, so they should have the new attribute. Maybe there is something messed up because we have converted the
int flagsto enumerations. I will investigate.jahmai-ca commentedon Nov 17, 2022
This causes a compile error in our Xamarin.Forms apps on Azure DevOps windows-2022 images.
Error CS0618: 'PackageManager.GetPackageInfo(string, PackageInfoFlags)' is obsolete: 'deprecated'This is weird since that signature should be the one that isn't deprecated:
https://developer.android.com/reference/android/content/pm/PackageManager#getPackageInfo(java.lang.String,%20android.content.pm.PackageManager.PackageInfoFlags)
The deprecated one is the int flags overload:
https://developer.android.com/reference/android/content/pm/PackageManager#getPackageInfo(java.lang.String,%20int)
But there appears to be no overload for (
int flags) in the Xamarin.Android references.So this is surely something that needs to be addressed as early as Xamarin.Android, let along NET6/7/8.
jpobst commentedon Nov 17, 2022
This appears to be a case of us making an unfortunate name choice a long time ago.
The original methods from Google are:
public abstract PackageInfo GetPackageInfo(VersionedPackage versionedPackage, int flags)public abstract PackageInfo GetPackageInfo(string packageName, int flags)We want our APIs to be a little easier to use, so we converted the
int flagsparameter to an enum calledPackageInfoFlags, so they now look like this:public abstract PackageInfo GetPackageInfo(VersionedPackage versionedPackage, [GeneratedEnum] PackageInfoFlags flags)public abstract PackageInfo GetPackageInfo(string packageName, [GeneratedEnum] PackageInfoFlags flags)In API-33, it looks like Google has done the same thing we did and introduced new overloads that take an "enum-like" Java type:
public virtual PackageInfo GetPackageInfo(VersionedPackage versionedPackage, PackageManager.PackageInfoFlags flags)public virtual PackageInfo GetPackageInfo(string packageName, PackageManager.PackageInfoFlags flags)Note that instead of our enum
PackageInfoFlagsthese use a Java classPackageManager.PackageInfoFlagswhich has the same name as our enum but is a different type.Thus you have to look closer to see that methods that take the enum
PackageInfoFlags(theint flagsJava methods) are the ones that are deprecated, and the new methods that take the Java typePackageManager.PackageInfoFlagsare not deprecated.[Obsolete]does not produce an error, it produces a warning. You likely have some form of<TreatWarningsAsErrors>or<WarningsAsErrors>in your project file. You will need to suppress the warning using the regular C# mechanisms so your project does not treat it as an error.jahmai-ca commentedon Nov 17, 2022
We don't. We actually use [Obsolete] ourselves, which generates
warning CS0618without any errors. This specific one gets converted toError CS0618: 'PackageManager.GetPackageInfo(string, PackageInfoFlags)' is obsolete: 'deprecated'and I don't know why.We're going to suppress it in code with
#pragma, but ultimately we want to be able to call the appropriate version of GetPackageInfo since we target API 33 but support down to 23, and don't want to have to upgrade to NET8 to do that...jahmai-ca commentedon Nov 17, 2022
This may also apply to
PackageManager.QueryIntentActivitieswith a similar issue of enum/int flags.jpobst commentedon Jan 5, 2023
This should be fixed as a result of:
[api-merge] Correctly compute //method/@deprecated-since (dotnet#7645)