From 6f46c7f4a298951d1f2d8e974a8a01b038ce8859 Mon Sep 17 00:00:00 2001
From: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date: Wed, 4 Jan 2023 14:25:18 -0600
Subject: [PATCH 1/2] Address breaking changes in Java.Interop

Context: https://github.com/xamarin/java.interop/pull/1069

Any place we had:

    TypeDefinitionCache?
    IMetadataResolver?

These no longer allow nulls, and so overloads that use `Obsolete` now
emit errors instead of warnings:

    [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)]
    public static MethodDefinition GetBaseDefinition (this MethodDefinition method) =>
        GetBaseDefinition (method, resolver: null!);

This results in 3 compiler errors in xamarin-android:

    src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(65,11): error CS0619: 'TypeDefinitionRocks.IsSubclassOf(TypeDefinition, string)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'
    src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(268,12): error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'
    src\Xamarin.Android.Build.Tasks\Utilities\ManifestDocumentElement.cs(28,11): error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'

After these changes, it appears we will improve the performance
further of apps that use:

* `ApplicationAttribute.BackupAgent`
* `ApplicationAttribute.Name`
* `AndroidManifest.xml` attributes that take a `System.Type` values

Additionally, fix NRE in the linker:

    Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
    at Java.Interop.Tools.Cecil.TypeDefinitionRocks.GetBaseType(TypeDefinition type, IMetadataResolver resolver) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 21
    at Java.Interop.Tools.Cecil.TypeDefinitionRocks.GetTypeAndBaseTypes(TypeDefinition type, IMetadataResolver resolver)+MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 36
    at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName, IMetadataResolver resolver) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 87
    at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessType(TypeDefinition type) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs:line 81
    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
    at Mono.Linker.Steps.MarkStep.MarkField(FieldDefinition field, DependencyInfo& reason, MessageOrigin& origin)
    at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason)
    at Mono.Linker.Steps.MarkStep.MarkEntireAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.MarkStep.MarkAssembly(AssemblyDefinition assembly, DependencyInfo reason)
    at Mono.Linker.Steps.MarkStep.MarkModule(ModuleDefinition module, DependencyInfo reason)
    at Mono.Linker.Steps.MarkStep.ProcessMarkedPending()
    at Mono.Linker.Steps.MarkStep.Initialize()
    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at Mono.Linker.Driver.Run(ILogger customLogger)
    at Mono.Linker.Driver.Main(String[] args)

This was caused by removing null checks in Java.Interop.
---
 .../MonoDroid.Tuner/FixAbstractMethodsStep.cs |   1 +
 .../Mono.Android/ActivityAttribute.Partial.cs |   4 +-
 .../ApplicationAttribute.Partial.cs           |  14 +--
 .../BroadcastReceiverAttribute.Partial.cs     |   4 +-
 .../ContentProviderAttribute.Partial.cs       |   4 +-
 .../GrantUriPermissionAttribute.Partial.cs    |   4 +-
 .../InstrumentationAttribute.Partial.cs       |   4 +-
 .../Mono.Android/LayoutAttribute.Partial.cs   |   6 +-
 .../Mono.Android/MetaDataAttribute.Partial.cs |   4 +-
 .../PermissionAttribute.Partial.cs            |   4 +-
 .../PermissionGroupAttribute.Partial.cs       |   4 +-
 .../PermissionTreeAttribute.Partial.cs        |   4 +-
 .../Mono.Android/ServiceAttribute.Partial.cs  |   4 +-
 .../SupportsGLTextureAttribute.Partial.cs     |   4 +-
 .../UsesConfigurationAttribute.Partial.cs     |   4 +-
 .../UsesFeatureAttribute.Partial.cs           |   4 +-
 .../UsesLibraryAttribute.Partial.cs           |   4 +-
 .../UsesPermissionAttribute.Partial.cs        |   4 +-
 .../Tasks/GenerateJavaStubs.cs                |   2 +-
 .../Utilities/ManifestDocument.cs             | 102 +++++++++---------
 .../Utilities/ManifestDocumentElement.cs      |  58 +++++-----
 21 files changed, 123 insertions(+), 120 deletions(-)

diff --git a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs
index 107d3b53f64..1143bc1bef1 100644
--- a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs
+++ b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs
@@ -33,6 +33,7 @@ public class FixAbstractMethodsStep :
 #if ILLINK
 		public override void Initialize (LinkContext context, MarkContext markContext)
 		{
+			this.cache = context;
 			base.Initialize (context, markContext);
 			markContext.RegisterMarkTypeAction (type => ProcessType (type));
 		}
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/ActivityAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/ActivityAttribute.Partial.cs
index dbd4e984333..a51762461b8 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/ActivityAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/ActivityAttribute.Partial.cs
@@ -347,9 +347,9 @@ public static ActivityAttribute FromTypeDefinition (TypeDefinition type)
 			return self;
 		}
 
-		internal XElement ToElement (IAssemblyResolver resolver, string packageName, int targetSdkVersion)
+		internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache, int targetSdkVersion)
 		{
-			return mapping.ToElement (this, specified, packageName, type, resolver, targetSdkVersion);
+			return mapping.ToElement (this, specified, packageName, cache, type, resolver, targetSdkVersion);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/ApplicationAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/ApplicationAttribute.Partial.cs
index a04b0c436bd..4cf9e4a494d 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/ApplicationAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/ApplicationAttribute.Partial.cs
@@ -59,15 +59,15 @@ partial class ApplicationAttribute {
 			  "BackupAgent",
 			  "backupAgent",
 			  (self, value) => self._BackupAgent  = (string) value,
-				(self, p, r)  => {
+				(self, p, r, cache)  => {
 					var typeDef = ManifestDocumentElement.ResolveType (self._BackupAgent, p, r);
 
-					if (!typeDef.IsSubclassOf ("Android.App.Backup.BackupAgent"))
+					if (!typeDef.IsSubclassOf ("Android.App.Backup.BackupAgent", cache))
 						throw new InvalidOperationException (
 								string.Format ("The Type '{0}', referenced by the Android.App.ApplicationAttribute.BackupAgent property, must be a subclass of the type Android.App.Backup.BackupAgent.",
 									typeDef.FullName));
 
-					return ManifestDocumentElement.ToString (typeDef);
+					return ManifestDocumentElement.ToString (typeDef, cache);
 			  }
 			}, {
 			  "BackupInForeground",
@@ -256,16 +256,16 @@ public static ApplicationAttribute FromCustomAttributeProvider (ICustomAttribute
 			return self;
 		}
 
-		internal XElement ToElement (IAssemblyResolver resolver, string packageName)
+		internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName, provider, resolver);
+			return mapping.ToElement (this, specified, packageName, cache, provider, resolver);
 		}
 
-		static string ToNameAttribute (ApplicationAttribute self)
+		static string ToNameAttribute (ApplicationAttribute self, ICustomAttributeProvider provider, IAssemblyResolver resolver, TypeDefinitionCache cache)
 		{
 			var type = self.provider as TypeDefinition;
 			if (string.IsNullOrEmpty (self.Name) && type != null)
-				return JavaNativeTypeManager.ToJniName (type).Replace ('/', '.');
+				return JavaNativeTypeManager.ToJniName (type, cache).Replace ('/', '.');
 
 			return self.Name;
 		}
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/BroadcastReceiverAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/BroadcastReceiverAttribute.Partial.cs
index 853dba23083..2b784d11c2b 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/BroadcastReceiverAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/BroadcastReceiverAttribute.Partial.cs
@@ -82,9 +82,9 @@ public static BroadcastReceiverAttribute FromTypeDefinition (TypeDefinition type
 			return self;
 		}
 
-		public XElement ToElement (string packageName)
+		public XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/ContentProviderAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/ContentProviderAttribute.Partial.cs
index 00d38c3ccbf..dfd659d0a40 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/ContentProviderAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/ContentProviderAttribute.Partial.cs
@@ -118,9 +118,9 @@ public static ContentProviderAttribute FromTypeDefinition (TypeDefinition type)
 			return self;
 		}
 
-		public XElement ToElement (string packageName)
+		public XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/GrantUriPermissionAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/GrantUriPermissionAttribute.Partial.cs
index bee41a98070..15dc8907619 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/GrantUriPermissionAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/GrantUriPermissionAttribute.Partial.cs
@@ -45,9 +45,9 @@ public static IEnumerable<GrantUriPermissionAttribute> FromTypeDefinition (TypeD
 			}
 		}
 
-		public XElement ToElement (string packageName)
+		public XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/InstrumentationAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/InstrumentationAttribute.Partial.cs
index 7f42c7847ae..1b31e8e681c 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/InstrumentationAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/InstrumentationAttribute.Partial.cs
@@ -76,9 +76,9 @@ public void SetTargetPackage (string package)
 			specified.Add ("TargetPackage");
 		}
 
-		public XElement ToElement (string packageName)
+		public XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/LayoutAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/LayoutAttribute.Partial.cs
index 5811970466b..43bcf8e9438 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/LayoutAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/LayoutAttribute.Partial.cs
@@ -1,4 +1,4 @@
-﻿using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Xml.Linq;
@@ -62,9 +62,9 @@ public static LayoutAttribute FromTypeDefinition (TypeDefinition type)
 			return self;
 		}
 
-		internal XElement ToElement (IAssemblyResolver resolver, string packageName)
+		internal XElement ToElement (IAssemblyResolver resolver, string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName, type, resolver);
+			return mapping.ToElement (this, specified, packageName, cache, type, resolver);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/MetaDataAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/MetaDataAttribute.Partial.cs
index 16755af4e7d..02b58638b0c 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/MetaDataAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/MetaDataAttribute.Partial.cs
@@ -46,9 +46,9 @@ public static IEnumerable<MetaDataAttribute> FromCustomAttributeProvider (ICusto
 			}
 		}
 
-		public XElement ToElement (string packageName)
+		public XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionAttribute.Partial.cs
index 9c874258873..6980b73d273 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionAttribute.Partial.cs
@@ -72,9 +72,9 @@ public static IEnumerable<PermissionAttribute> FromCustomAttributeProvider (ICus
 			}
 		}
 
-		internal XElement ToElement (string packageName)
+		internal XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 
 		internal class PermissionAttributeComparer : IEqualityComparer<PermissionAttribute>
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionGroupAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionGroupAttribute.Partial.cs
index fecc9bec0c1..37292f0f557 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionGroupAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionGroupAttribute.Partial.cs
@@ -62,9 +62,9 @@ public static IEnumerable<PermissionGroupAttribute> FromCustomAttributeProvider
 			}
 		}
 
-		internal XElement ToElement (string packageName)
+		internal XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 
 		internal class PermissionGroupAttributeComparer : IEqualityComparer<PermissionGroupAttribute>
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionTreeAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionTreeAttribute.Partial.cs
index 0ec9b71b3a2..266c09bd09b 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionTreeAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/PermissionTreeAttribute.Partial.cs
@@ -57,9 +57,9 @@ public static IEnumerable<PermissionTreeAttribute> FromCustomAttributeProvider (
 			}
 		}
 
-		internal XElement ToElement (string packageName)
+		internal XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 
 		internal class PermissionTreeAttributeComparer : IEqualityComparer<PermissionTreeAttribute>
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/ServiceAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/ServiceAttribute.Partial.cs
index c3a55453fdb..0c7b8ae56ec 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/ServiceAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/ServiceAttribute.Partial.cs
@@ -90,9 +90,9 @@ public static ServiceAttribute FromTypeDefinition (TypeDefinition type)
 			return self;
 		}
 
-		public XElement ToElement (string packageName)
+		public XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/SupportsGLTextureAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/SupportsGLTextureAttribute.Partial.cs
index 603b0d0bdc8..5f93492aeba 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/SupportsGLTextureAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/SupportsGLTextureAttribute.Partial.cs
@@ -20,9 +20,9 @@ partial class SupportsGLTextureAttribute
 		};
 
 
-		internal XElement ToElement (string packageName)
+		internal XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 
 		ICollection<string> specified;
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesConfigurationAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesConfigurationAttribute.Partial.cs
index 8d497052234..6d06b0fffae 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesConfigurationAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesConfigurationAttribute.Partial.cs
@@ -42,9 +42,9 @@ partial class UsesConfigurationAttribute	{
 			}
 		};
 
-		internal XElement ToElement (string packageName)
+		internal XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 
 		ICollection<string> specified;
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesFeatureAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesFeatureAttribute.Partial.cs
index 420afd35dcb..e638b939b33 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesFeatureAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesFeatureAttribute.Partial.cs
@@ -43,9 +43,9 @@ internal string GLESVesionAsString ()
 			return String.Format("0x{0}", GLESVersion.ToString("X8"));
 		}
 
-		internal XElement ToElement (string packageName)
+		internal XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 
 		ICollection<string> specified;
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesLibraryAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesLibraryAttribute.Partial.cs
index e7d85a35bf3..6ca0147370d 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesLibraryAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesLibraryAttribute.Partial.cs
@@ -58,9 +58,9 @@ public static IEnumerable<UsesLibraryAttribute> FromCustomAttributeProvider (ICu
 			}
 		}
 
-		public XElement ToElement (string packageName)
+		public XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 	}
 }
diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesPermissionAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesPermissionAttribute.Partial.cs
index 488e6b085cd..4e3792883b5 100644
--- a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesPermissionAttribute.Partial.cs
+++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesPermissionAttribute.Partial.cs
@@ -54,9 +54,9 @@ public static IEnumerable<UsesPermissionAttribute> FromCustomAttributeProvider (
 			}
 		}
 
-		public XElement ToElement (string packageName)
+		public XElement ToElement (string packageName, TypeDefinitionCache cache)
 		{
-			return mapping.ToElement (this, specified, packageName);
+			return mapping.ToElement (this, specified, packageName, cache);
 		}
 
 		internal class UsesPermissionComparer : IEqualityComparer<UsesPermissionAttribute>
diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
index d82c2f10b00..c6896962d1d 100644
--- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
@@ -483,7 +483,7 @@ bool CreateJavaSources (IEnumerable<TypeDefinition> javaTypes, TypeDefinitionCac
 						jti.Generate (writer);
 						if (useMarshalMethods) {
 							if (classifier.FoundDynamicallyRegisteredMethods (t)) {
-								Log.LogWarning ($"Type '{t.GetAssemblyQualifiedName ()}' will register some of its Java override methods dynamically. This may adversely affect runtime performance. See preceding warnings for names of dynamically registered methods.");
+								Log.LogWarning ($"Type '{t.GetAssemblyQualifiedName (cache)}' will register some of its Java override methods dynamically. This may adversely affect runtime performance. See preceding warnings for names of dynamically registered methods.");
 							}
 						}
 						writer.Flush ();
diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
index 30721433687..3f648c5cfcb 100644
--- a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
+++ b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
@@ -344,7 +344,7 @@ public IList<string> Merge (TaskLoggingHelper log, TypeDefinitionCache cache, Li
 					continue;
 				}
 
-				Func<TypeDefinition, string, int, XElement> generator = GetGenerator (t, cache);
+				Func<TypeDefinition, string, TypeDefinitionCache, int, XElement> generator = GetGenerator (t, cache);
 				if (generator == null)
 					continue;
 
@@ -352,7 +352,7 @@ public IList<string> Merge (TaskLoggingHelper log, TypeDefinitionCache cache, Li
 					(string name, string compatName) = GetNames (t, cache);
 					// activity not present: create a launcher for it IFF it has attribute
 					if (!existingTypes.Contains (name) && !existingTypes.Contains (compatName)) {
-						XElement fromCode = generator (t, name, targetSdkVersionValue);
+						XElement fromCode = generator (t, name, cache, targetSdkVersionValue);
 						if (fromCode == null)
 							continue;
 
@@ -435,12 +435,12 @@ public IList<string> Merge (TaskLoggingHelper log, TypeDefinitionCache cache, Li
 			}
 
 			AddInstrumentations (manifest, subclasses, targetSdkVersionValue, cache);
-			AddPermissions (app);
-			AddPermissionGroups (app);
-			AddPermissionTrees (app);
-			AddUsesPermissions (app);
-			AddUsesFeatures (app);
-			AddSupportsGLTextures (app);
+			AddPermissions (app, cache);
+			AddPermissionGroups (app, cache);
+			AddPermissionTrees (app, cache);
+			AddUsesPermissions (app, cache);
+			AddUsesFeatures (app, cache);
+			AddSupportsGLTextures (app, cache);
 
 			if (targetSdkVersionValue >= 23) {
 				if (ForceExtractNativeLibs || app.Attribute (androidNs + "extractNativeLibs") == null)
@@ -553,16 +553,16 @@ IEnumerable<XNode> FixupNameElements(string packageName, IEnumerable<XNode> node
 			return nodes;
 		}
 
-		Func<TypeDefinition, string, int, XElement> GetGenerator (TypeDefinition type, TypeDefinitionCache cache)
+		Func<TypeDefinition, string, TypeDefinitionCache, int, XElement> GetGenerator (TypeDefinition type, TypeDefinitionCache cache)
 		{
 			if (type.IsSubclassOf ("Android.App.Activity", cache))
 				return ActivityFromTypeDefinition;
 			if (type.IsSubclassOf ("Android.App.Service", cache))
-				return (t, name, v) => ToElement (t, name, ServiceAttribute.FromTypeDefinition, x => x.ToElement (PackageName));
+				return (t, name, c, v) => ToElement (t, name, ServiceAttribute.FromTypeDefinition, x => x.ToElement (PackageName, c), c);
 			if (type.IsSubclassOf ("Android.Content.BroadcastReceiver", cache))
-				return (t, name, v) => ToElement (t, name, BroadcastReceiverAttribute.FromTypeDefinition, x => x.ToElement (PackageName));
+				return (t, name, c, v) => ToElement (t, name, BroadcastReceiverAttribute.FromTypeDefinition, x => x.ToElement (PackageName, c), c);
 			if (type.IsSubclassOf ("Android.Content.ContentProvider", cache))
-				return (t, name, v) => ToProviderElement (t, name);
+				return (t, name, c, v) => ToProviderElement (t, name, c);
 			return null;
 		}
 
@@ -621,7 +621,7 @@ XElement CreateApplicationElement (XElement manifest, string applicationClass, L
 			bool needManifestAdd = true;
 
 			if (appAttr != null) {
-				var newapp = appAttr.ToElement (Resolver, PackageName);
+				var newapp = appAttr.ToElement (Resolver, PackageName, cache);
 				if (application == null)
 					application = newapp;
 				else {
@@ -636,13 +636,13 @@ XElement CreateApplicationElement (XElement manifest, string applicationClass, L
 				application = new XElement ("application");
 			else
 				needManifestAdd = false;
-			application.Add (metadata.Select (md => md.ToElement (PackageName)));
+			application.Add (metadata.Select (md => md.ToElement (PackageName, cache)));
 
 			if (needManifestAdd)
 				manifest.Add (application);
 
-			AddUsesLibraries (application, usesLibraryAttrs);
-			AddUsesConfigurations (application, usesConfigurationattrs);
+			AddUsesLibraries (application, usesLibraryAttrs, cache);
+			AddUsesConfigurations (application, usesConfigurationattrs, cache);
 
 			if (applicationClass != null && application.Attribute (androidNs + "name") == null)
 				application.Add (new XAttribute (androidNs + "name", applicationClass));
@@ -729,41 +729,43 @@ public bool DirectBootAware ()
 			return false;
 		}
 
-		XElement ActivityFromTypeDefinition (TypeDefinition type, string name, int targetSdkVersion)
+		XElement ActivityFromTypeDefinition (TypeDefinition type, string name, TypeDefinitionCache cache, int targetSdkVersion)
 		{
 			if (name.StartsWith ("_", StringComparison.Ordinal))
 				throw new InvalidActivityNameException (string.Format ("Activity name '{0}' is invalid, because activity namespaces may not begin with an underscore.", type.FullName));
 
 			return ToElement (type, name,
 					ActivityAttribute.FromTypeDefinition,
-					aa => aa.ToElement (Resolver, PackageName, targetSdkVersion),
+					aa => aa.ToElement (Resolver, PackageName, cache, targetSdkVersion),
 					(aa, element) => {
 						if (aa.MainLauncher)
 							AddLauncherIntentElements (element);
 						var la = LayoutAttribute.FromTypeDefinition (type);
 						if (la != null)
-							element.Add (la.ToElement (Resolver, PackageName));
-					});
+							element.Add (la.ToElement (Resolver, PackageName, cache));
+					},
+					cache);
 		}
 
-		XElement InstrumentationFromTypeDefinition (TypeDefinition type, string name, int targetSdkVersion)
+		XElement InstrumentationFromTypeDefinition (TypeDefinition type, string name, TypeDefinitionCache cache)
 		{
 			return ToElement (type, name,
 					t => InstrumentationAttribute.FromCustomAttributeProvider (t).FirstOrDefault (),
 					ia => {
 						if (ia.TargetPackage == null)
 							ia.SetTargetPackage (PackageName);
-						return ia.ToElement (PackageName);
-					});
+						return ia.ToElement (PackageName, cache);
+					},
+					cache);
 		}
 
-		XElement ToElement<TAttribute> (TypeDefinition type, string name, Func<TypeDefinition, TAttribute> parser, Func<TAttribute, XElement> toElement)
+		XElement ToElement<TAttribute> (TypeDefinition type, string name, Func<TypeDefinition, TAttribute> parser, Func<TAttribute, XElement> toElement, TypeDefinitionCache cache)
 			where TAttribute : class
 		{
-			return ToElement (type, name, parser, toElement, null);
+			return ToElement (type, name, parser, toElement, update: null, cache);
 		}
 
-		XElement ToElement<TAttribute> (TypeDefinition type, string name, Func<TypeDefinition, TAttribute> parser, Func<TAttribute, XElement> toElement, Action<TAttribute, XElement> update)
+		XElement ToElement<TAttribute> (TypeDefinition type, string name, Func<TypeDefinition, TAttribute> parser, Func<TAttribute, XElement> toElement, Action<TAttribute, XElement> update, TypeDefinitionCache cache)
 			where TAttribute : class
 		{
 			TAttribute attr = parser (type);
@@ -776,14 +778,14 @@ XElement ToElement<TAttribute> (TypeDefinition type, string name, Func<TypeDefin
 			XElement element = toElement (attr);
 			if (element.Attribute (attName) == null)
 				element.Add (new XAttribute (attName, name));
-			element.Add (metadata.Select (md => md.ToElement (PackageName)));
+			element.Add (metadata.Select (md => md.ToElement (PackageName, cache)));
 			element.Add (intents.Select (intent => intent.ToElement (PackageName)));
 			if (update != null)
 				update (attr, element);
 			return element;
 		}
 
-		XElement ToProviderElement (TypeDefinition type, string name)
+		XElement ToProviderElement (TypeDefinition type, string name, TypeDefinitionCache cache)
 		{
 			var attr = ContentProviderAttribute.FromTypeDefinition (type);
 			if (attr == null)
@@ -793,11 +795,11 @@ XElement ToProviderElement (TypeDefinition type, string name)
 			IEnumerable<GrantUriPermissionAttribute> grants = GrantUriPermissionAttribute.FromTypeDefinition (type);
 			IEnumerable<IntentFilterAttribute> intents = IntentFilterAttribute.FromTypeDefinition (type);
 
-			XElement element = attr.ToElement (PackageName);
+			XElement element = attr.ToElement (PackageName, cache);
 			if (element.Attribute (attName) == null)
 				element.Add (new XAttribute (attName, name));
-			element.Add (metadata.Select (md => md.ToElement (PackageName)));
-			element.Add (grants.Select (intent => intent.ToElement (PackageName)));
+			element.Add (metadata.Select (md => md.ToElement (PackageName, cache)));
+			element.Add (grants.Select (intent => intent.ToElement (PackageName, cache)));
 			element.Add (intents.Select (intent => intent.ToElement (PackageName)));
 
 			return element;
@@ -830,17 +832,17 @@ public void AddInternetPermissionForDebugger ()
 				app.AddBeforeSelf (new XElement ("uses-permission", new XAttribute (attName, permInternet)));
 		}
 
-		void AddPermissions (XElement application)
+		void AddPermissions (XElement application, TypeDefinitionCache cache)
 		{
 			var assemblyAttrs =
 				Assemblies.SelectMany (path => PermissionAttribute.FromCustomAttributeProvider (Resolver.GetAssembly (path)));
 			// Add unique permissions to the manifest
 			foreach (var pa in assemblyAttrs.Distinct (new PermissionAttribute.PermissionAttributeComparer ()))
 				if (!application.Parent.Descendants ("permission").Any (x => (string)x.Attribute (attName) == pa.Name))
-					application.AddBeforeSelf (pa.ToElement (PackageName));
+					application.AddBeforeSelf (pa.ToElement (PackageName, cache));
 		}
 
-		void AddPermissionGroups (XElement application)
+		void AddPermissionGroups (XElement application, TypeDefinitionCache cache)
 		{
 			var assemblyAttrs =
 				Assemblies.SelectMany (path => PermissionGroupAttribute.FromCustomAttributeProvider (Resolver.GetAssembly (path)));
@@ -848,10 +850,10 @@ void AddPermissionGroups (XElement application)
 			// Add unique permissionGroups to the manifest
 			foreach (var pga in assemblyAttrs.Distinct (new PermissionGroupAttribute.PermissionGroupAttributeComparer ()))
 				if (!application.Parent.Descendants ("permissionGroup").Any (x => (string)x.Attribute (attName) == pga.Name))
-					application.AddBeforeSelf (pga.ToElement (PackageName));
+					application.AddBeforeSelf (pga.ToElement (PackageName, cache));
 		}
 
-		void AddPermissionTrees (XElement application)
+		void AddPermissionTrees (XElement application, TypeDefinitionCache cache)
 		{
 			var assemblyAttrs =
 				Assemblies.SelectMany (path => PermissionTreeAttribute.FromCustomAttributeProvider (Resolver.GetAssembly (path)));
@@ -859,10 +861,10 @@ void AddPermissionTrees (XElement application)
 			// Add unique permissionGroups to the manifest
 			foreach (var pta in assemblyAttrs.Distinct (new PermissionTreeAttribute.PermissionTreeAttributeComparer ()))
 				if (!application.Parent.Descendants ("permissionTree").Any (x => (string)x.Attribute (attName) == pta.Name))
-					application.AddBeforeSelf (pta.ToElement (PackageName));
+					application.AddBeforeSelf (pta.ToElement (PackageName, cache));
 		}
 
-		void AddUsesPermissions (XElement application)
+		void AddUsesPermissions (XElement application, TypeDefinitionCache cache)
 		{
 			var assemblyAttrs =
 				Assemblies.SelectMany (path => UsesPermissionAttribute.FromCustomAttributeProvider (Resolver.GetAssembly (path)));
@@ -870,23 +872,23 @@ void AddUsesPermissions (XElement application)
 			// Add unique permissions to the manifest
 			foreach (var upa in assemblyAttrs.Distinct (new UsesPermissionAttribute.UsesPermissionComparer ()))
 				if (!application.Parent.Descendants ("uses-permission").Any (x => (string)x.Attribute (attName) == upa.Name))
-					application.AddBeforeSelf (upa.ToElement (PackageName));
+					application.AddBeforeSelf (upa.ToElement (PackageName, cache));
 		}
-		void AddUsesConfigurations (XElement application, IEnumerable<UsesConfigurationAttribute> configs)
+		void AddUsesConfigurations (XElement application, IEnumerable<UsesConfigurationAttribute> configs, TypeDefinitionCache cache)
 		{
 			foreach (var uca in configs)
-				application.Add (uca.ToElement (PackageName));
+				application.Add (uca.ToElement (PackageName, cache));
 		}
 
-		void AddUsesLibraries (XElement application, IEnumerable<UsesLibraryAttribute> libraries)
+		void AddUsesLibraries (XElement application, IEnumerable<UsesLibraryAttribute> libraries, TypeDefinitionCache cache)
 		{
 			// Add unique libraries to the manifest
 			foreach (var ula in libraries)
 				if (!application.Descendants ("uses-library").Any (x => (string)x.Attribute (attName) == ula.Name))
-					application.Add (ula.ToElement (PackageName));
+					application.Add (ula.ToElement (PackageName, cache));
 		}
 
-		void AddUsesFeatures (XElement application)
+		void AddUsesFeatures (XElement application, TypeDefinitionCache cache)
 		{
 			var assemblyAttrs =
 				Assemblies.SelectMany (path => UsesFeatureAttribute.FromCustomAttributeProvider (Resolver.GetAssembly (path)));
@@ -895,19 +897,19 @@ void AddUsesFeatures (XElement application)
 			foreach (var feature in assemblyAttrs) {
 				if (!string.IsNullOrEmpty(feature.Name) && feature.GLESVersion == 0) {
 					if (!application.Parent.Descendants ("uses-feature").Any (x => (string)x.Attribute (attName) == feature.Name)) {
-						application.AddBeforeSelf (feature.ToElement (PackageName));
+						application.AddBeforeSelf (feature.ToElement (PackageName, cache));
 					}
 				}
 				if (feature.GLESVersion != 0){
 					if (!application.Parent.Descendants ("uses-feature").Any (x => (string)x.Attribute (androidNs+"glEsVersion") == feature.GLESVesionAsString())) {
-						application.AddBeforeSelf (feature.ToElement (PackageName));
+						application.AddBeforeSelf (feature.ToElement (PackageName, cache));
 					}
 				}
 
 			}
 		}
 
-		void AddSupportsGLTextures (XElement application)
+		void AddSupportsGLTextures (XElement application, TypeDefinitionCache cache)
 		{
 			var assemblyAttrs =
 				Assemblies.SelectMany (path => SupportsGLTextureAttribute.FromCustomAttributeProvider (Resolver.GetAssembly (path)));
@@ -915,7 +917,7 @@ void AddSupportsGLTextures (XElement application)
 			// Add unique items by Name to the manifest
 			foreach (var feature in assemblyAttrs) {
 				if (!application.Parent.Descendants ("supports-gl-texture").Any (x => (string)x.Attribute (attName) == feature.Name)) {
-					application.AddBeforeSelf (feature.ToElement (PackageName));
+					application.AddBeforeSelf (feature.ToElement (PackageName, cache));
 				}
 			}
 		}
@@ -930,12 +932,12 @@ void AddInstrumentations (XElement manifest, IList<TypeDefinition> subclasses, i
 				if (ia.TargetPackage == null)
 					ia.SetTargetPackage (PackageName);
 				if (!manifest.Descendants ("instrumentation").Any (x => (string) x.Attribute (attName) == ia.Name))
-					manifest.Add (ia.ToElement (PackageName));
+					manifest.Add (ia.ToElement (PackageName, cache));
 			}
 
 			foreach (var type in subclasses)
 				if (type.IsSubclassOf ("Android.App.Instrumentation", cache)) {
-					var xe = InstrumentationFromTypeDefinition (type, JavaNativeTypeManager.ToJniName (type, cache).Replace ('/', '.'), targetSdkVersion);
+					var xe = InstrumentationFromTypeDefinition (type, JavaNativeTypeManager.ToJniName (type, cache).Replace ('/', '.'), cache);
 					if (xe != null)
 						manifest.Add (xe);
 				}
diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocumentElement.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocumentElement.cs
index b70ffd2ec31..959626874db 100644
--- a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocumentElement.cs
+++ b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocumentElement.cs
@@ -23,9 +23,9 @@ namespace Xamarin.Android.Manifest {
 
 	class ManifestDocumentElement {
 
-		public static string ToString (TypeDefinition typeDef)
+		public static string ToString (TypeDefinition typeDef, TypeDefinitionCache cache)
 		{
-			return JavaNativeTypeManager.ToJniName (typeDef).Replace ('/', '.');
+			return JavaNativeTypeManager.ToJniName (typeDef, cache).Replace ('/', '.');
 		}
 
 		public static TypeDefinition ResolveType (string type, ICustomAttributeProvider provider, IAssemblyResolver resolver)
@@ -80,7 +80,7 @@ class MappingInfo {
 			public Action<T, object>  Setter;
 			public Type               MemberType;
 			public Func<T, string>    AttributeValue;
-			public Func<T, ICustomAttributeProvider, IAssemblyResolver, string>    AttributeValue2;
+			public Func<T, ICustomAttributeProvider, IAssemblyResolver, TypeDefinitionCache, string>    AttributeValue2;
 		}
 
 		readonly IDictionary<string, MappingInfo>   Mappings = new Dictionary<string, MappingInfo> ();
@@ -104,7 +104,7 @@ public void Add (string member, string attributeName, Action<T, object> setter,
 			});
 		}
 
-		public void Add (string member, string attributeName, Action<T, object> setter, Func<T, ICustomAttributeProvider, IAssemblyResolver, string> attributeValue)
+		public void Add (string member, string attributeName, Action<T, object> setter, Func<T, ICustomAttributeProvider, IAssemblyResolver, TypeDefinitionCache, string> attributeValue)
 		{
 			Mappings.Add (member, new MappingInfo {
 					AttributeName   = attributeName,
@@ -130,19 +130,19 @@ public ICollection<string> Load (T value, CustomAttribute attribute)
 			return specified;
 		}
 
-		public XElement ToElement (T value, ICollection<string> specified, string packageName,
+		public XElement ToElement (T value, ICollection<string> specified, string packageName, TypeDefinitionCache cache,
 			ICustomAttributeProvider provider = null, IAssemblyResolver resolver = null, int targetSdkVersion = 0)
 		{
 			var r = new XElement (Element,
 					specified.OrderBy (e => e)
-					.Select (e => ToAttribute (e, value, packageName, provider, resolver, targetSdkVersion))
+					.Select (e => ToAttribute (e, value, packageName, provider, resolver, cache, targetSdkVersion))
 					.Where (a => a != null));
 			AndroidResource.UpdateXmlResource (r);
 			return r;
 		}
 
 		XAttribute ToAttribute (string name, T value, string packageName,
-			ICustomAttributeProvider provider, IAssemblyResolver resolver, int targetSdkVersion = 0)
+			ICustomAttributeProvider provider, IAssemblyResolver resolver, TypeDefinitionCache cache, int targetSdkVersion = 0)
 		{
 			if (!Mappings.ContainsKey (name))
 				throw new ArgumentException ("Invalid attribute name: " + name);
@@ -150,20 +150,20 @@ XAttribute ToAttribute (string name, T value, string packageName,
 			if (m.AttributeName == null)
 				return null;
 
-			string v = ToAttributeValue (name, value, provider, resolver,targetSdkVersion);
+			string v = ToAttributeValue (name, value, provider, resolver, cache, targetSdkVersion);
 			if (v == null)
 				return null;
 			v = v.Replace ("@PACKAGE_NAME@", packageName);
 			return new XAttribute (ManifestDocument.AndroidXmlNamespace + m.AttributeName, v);
 		}
 
-		string ToAttributeValue (string name, T value, ICustomAttributeProvider provider, IAssemblyResolver resolver, int targetSdkVersion = 0)
+		string ToAttributeValue (string name, T value, ICustomAttributeProvider provider, IAssemblyResolver resolver, TypeDefinitionCache cache, int targetSdkVersion = 0)
 		{
 			var m = Mappings [name];
 			if (m.AttributeValue != null)
 				return m.AttributeValue (value);
 			if (m.AttributeValue2 != null)
-				return m.AttributeValue2 (value, provider, resolver);
+				return m.AttributeValue2 (value, provider, resolver, cache);
 
 			if (m.Getter == null)
 				return null;
@@ -174,25 +174,25 @@ string ToAttributeValue (string name, T value, ICustomAttributeProvider provider
 
 			var t = m.MemberType ?? v.GetType ();
 			var c = ValueConverters [t];
-			return c (v, provider, resolver, targetSdkVersion);
+			return c (v, provider, resolver, targetSdkVersion, cache);
 		}
 
-		static readonly Dictionary<Type, Func<object, ICustomAttributeProvider, IAssemblyResolver, int, string>> ValueConverters = new Dictionary<Type, Func<object, ICustomAttributeProvider, IAssemblyResolver, int, string>> () {
-			{ typeof (bool),                (value, p, r, v) => ToString ((bool) value) },
-			{ typeof (int),                 (value, p, r, v) => value.ToString () },
-			{ typeof (float),               (value, p, r, v) => value.ToString () },
-			{ typeof (string),              (value, p, r, v) => value.ToString () },
-			{ typeof (ActivityPersistableMode),     (value, p, r, v) => ToString ((ActivityPersistableMode) value) },
-			{ typeof (ConfigChanges),       (value, p, r, v) => ToString ((ConfigChanges) value) },
-			{ typeof (DocumentLaunchMode),  (value, p, r, v) => ToString ((DocumentLaunchMode) value) },
-			{ typeof (ForegroundService),   (value, p, r, v) => ToString ((ForegroundService) value) },
-			{ typeof (LaunchMode),          (value, p, r, v) => ToString ((LaunchMode) value) },
-			{ typeof (Protection),          (value, p, r, v) => ToString ((Protection) value) },
-			{ typeof (ScreenOrientation),   (value, p, r, v) => ToString ((ScreenOrientation) value, v) },
-			{ typeof (SoftInput),           (value, p, r, v) => ToString ((SoftInput) value) },
-			{ typeof (UiOptions),           (value, p, r, v) => ToString ((UiOptions) value) },
-			{ typeof (Type),                (value, p, r, v) => ToString (value.ToString (), p, r) },
-			{ typeof (WindowRotationAnimation),     (value, p, r, v) => ToString ((WindowRotationAnimation) value) },
+		static readonly Dictionary<Type, Func<object, ICustomAttributeProvider, IAssemblyResolver, int, TypeDefinitionCache, string>> ValueConverters = new () {
+			{ typeof (bool),                (value, p, r, v, c) => ToString ((bool) value) },
+			{ typeof (int),                 (value, p, r, v, c) => value.ToString () },
+			{ typeof (float),               (value, p, r, v, c) => value.ToString () },
+			{ typeof (string),              (value, p, r, v, c) => value.ToString () },
+			{ typeof (ActivityPersistableMode),     (value, p, r, v, c) => ToString ((ActivityPersistableMode) value) },
+			{ typeof (ConfigChanges),       (value, p, r, v, c) => ToString ((ConfigChanges) value) },
+			{ typeof (DocumentLaunchMode),  (value, p, r, v, c) => ToString ((DocumentLaunchMode) value) },
+			{ typeof (ForegroundService),   (value, p, r, v, c) => ToString ((ForegroundService) value) },
+			{ typeof (LaunchMode),          (value, p, r, v, c) => ToString ((LaunchMode) value) },
+			{ typeof (Protection),          (value, p, r, v, c) => ToString ((Protection) value) },
+			{ typeof (ScreenOrientation),   (value, p, r, v, c) => ToString ((ScreenOrientation) value, v) },
+			{ typeof (SoftInput),           (value, p, r, v, c) => ToString ((SoftInput) value) },
+			{ typeof (UiOptions),           (value, p, r, v, c) => ToString ((UiOptions) value) },
+			{ typeof (Type),                (value, p, r, v, c) => ToString (value.ToString (), p, r, c) },
+			{ typeof (WindowRotationAnimation),     (value, p, r, v, c) => ToString ((WindowRotationAnimation) value) },
 		};
 
 		static string ToString (bool value)
@@ -360,10 +360,10 @@ static string ToString (WindowRotationAnimation value)
 			}
 		}
 
-		static string ToString (string value, ICustomAttributeProvider provider, IAssemblyResolver resolver)
+		static string ToString (string value, ICustomAttributeProvider provider, IAssemblyResolver resolver, TypeDefinitionCache cache)
 		{
 			var typeDef = ResolveType (value, provider, resolver);
-			return ToString (typeDef);
+			return ToString (typeDef, cache);
 		}
 
 		static string ToString (ForegroundService value)

From 046998b393fc0f59de7c2149b58a31bdf4a71818 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 9 Jan 2023 02:17:20 +0000
Subject: [PATCH 2/2] Bump external/Java.Interop from `f8d77fa` to `cf80deb`

Bumps [external/Java.Interop](https://github.com/xamarin/java.interop) from `f8d77fa` to `cf80deb`.
- [Release notes](https://github.com/xamarin/java.interop/releases)
- [Commits](https://github.com/xamarin/java.interop/compare/f8d77faf55347a58030a694332ba97f0dee88246...cf80deb7d2ad3c79abfd0140e4adee4376b41af5)

---
updated-dependencies:
- dependency-name: external/Java.Interop
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
---
 external/Java.Interop | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/external/Java.Interop b/external/Java.Interop
index f8d77faf553..cf80deb7d2a 160000
--- a/external/Java.Interop
+++ b/external/Java.Interop
@@ -1 +1 @@
-Subproject commit f8d77faf55347a58030a694332ba97f0dee88246
+Subproject commit cf80deb7d2ad3c79abfd0140e4adee4376b41af5
