From d8b0bd4efbcb054b9db99437d51ada118d8f912c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 30 Mar 2026 12:50:03 +0000 Subject: [PATCH 1/3] Initial plan From d0513d7a708674f483d477e44a5806d72a5104ed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 30 Mar 2026 14:23:25 +0000 Subject: [PATCH 2/3] Changes before error encountered Agent-Logs-Url: https://github.com/dotnet/android/sessions/cb7028a6-408a-410f-9e71-a8d53aa9c2ec Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com> --- src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs index 52eb8c826e4..b951a3bd1ee 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs @@ -42,7 +42,8 @@ internal static void Initialize () { var instance = new TrimmableTypeMap (); var previous = Interlocked.CompareExchange (ref s_instance, instance, null); - Debug.Assert (previous is null, "TrimmableTypeMap must only be created once."); + if (previous is not null) + return; instance.RegisterNatives (); } From 5a8136bba90b43cdeb30fa03e855c5a393d48cca Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 16:04:48 +0000 Subject: [PATCH 3/3] Use static Lock for thread-safe TrimmableTypeMap.Initialize Agent-Logs-Url: https://github.com/dotnet/android/sessions/fa7fcbcb-4960-4629-a4a2-627b90a610ec Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com> --- .../Microsoft.Android.Runtime/TrimmableTypeMap.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs index b951a3bd1ee..f2c535dd8c7 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.InteropServices; @@ -20,6 +19,7 @@ namespace Microsoft.Android.Runtime; /// class TrimmableTypeMap { + static readonly Lock s_initLock = new (); static TrimmableTypeMap? s_instance; internal static TrimmableTypeMap Instance => @@ -40,12 +40,17 @@ class TrimmableTypeMap /// internal static void Initialize () { - var instance = new TrimmableTypeMap (); - var previous = Interlocked.CompareExchange (ref s_instance, instance, null); - if (previous is not null) + if (s_instance is not null) return; - instance.RegisterNatives (); + lock (s_initLock) { + if (s_instance is not null) + return; + + var instance = new TrimmableTypeMap (); + instance.RegisterNatives (); + s_instance = instance; + } } ///