diff --git a/src/Mono.Android/Java.Interop/TypeManager.cs b/src/Mono.Android/Java.Interop/TypeManager.cs index cc0b22936bd..b00ea6056b0 100644 --- a/src/Mono.Android/Java.Interop/TypeManager.cs +++ b/src/Mono.Android/Java.Interop/TypeManager.cs @@ -453,47 +453,23 @@ public static void RegisterType (string java_class, Type t) } } - static Dictionary>>? packageLookup; - - [MemberNotNull (nameof (packageLookup))] - static void LazyInitPackageLookup () - { - if (packageLookup == null) - packageLookup = new Dictionary>> (StringComparer.Ordinal); - } - + const string TypeRegistrationNotSupported = + "Java package type registration is no longer supported. Java-to-managed type resolution now goes through the native and trimmable type maps."; + + // The package-based Java-to-managed type registration fallback was removed + // (https://github.com/dotnet/android/issues/11663); type resolution now goes + // through the native / trimmable type map, and the generator no longer emits + // the `Java.Interop.__TypeRegistrations` class that called these methods. These + // shipped public APIs are retained for binary compatibility but now throw, as + // they can no longer register anything. public static void RegisterPackage (string package, Converter lookup) { - LazyInitPackageLookup (); - - lock (packageLookup!) { - if (!packageLookup.TryGetValue (package, out var lookups)) - packageLookup.Add (package, lookups = new List> ()); - lookups.Add (lookup); - } + throw new NotSupportedException (TypeRegistrationNotSupported); } public static void RegisterPackages (string[] packages, Converter[] lookups) { - LazyInitPackageLookup (); - - if (packages == null) - throw new ArgumentNullException ("packages"); - if (lookups == null) - throw new ArgumentNullException ("lookups"); - if (packages.Length != lookups.Length) - throw new ArgumentException ("`packages` and `lookups` arrays must have same number of elements."); - - lock (packageLookup!) { - for (int i = 0; i < packages.Length; ++i) { - string package = packages [i]; - var lookup = lookups [i]; - - if (!packageLookup.TryGetValue (package, out var _lookups)) - packageLookup.Add (package, _lookups = new List> ()); - _lookups.Add (lookup); - } - } + throw new NotSupportedException (TypeRegistrationNotSupported); } [Register ("mono/android/TypeManager", DoNotGenerateAcw = true)]