Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] fix ArgumentException in GenerateCompre…
Browse files Browse the repository at this point in the history
…ssedAssembliesNativeSourceFiles (#6032)

Context: https://dev.azure.com/xamarin/public/_build/results?buildId=41853&view=logs&j=9cf5f8f4-c6e1-5b84-8b95-5f96f5b2da57&t=837f1816-7880-57fc-23bc-a709d74f8097&l=22687

dotnet/maui is hitting a build error, such as:

    error XAGCANSF7004: System.ArgumentException: An entry with the same key already exists.
    error XAGCANSF7004:    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
    error XAGCANSF7004:    at System.Collections.Generic.TreeSet`1.AddIfNotPresent(T item)
    error XAGCANSF7004:    at System.Collections.Generic.SortedDictionary`2.Add(TKey key, TValue value)
    error XAGCANSF7004:    at Xamarin.Android.Tasks.GenerateCompressedAssembliesNativeSourceFiles.GenerateCompressedAssemblySources()
    error XAGCANSF7004:    at Xamarin.Android.Tasks.GenerateCompressedAssembliesNativeSourceFiles.RunTask()
    error XAGCANSF7004:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

We believe there is somehow a duplicate assembly, but hard to tell
what is happening exactly from the `.binlog`.

Reviewing the `<GenerateCompressedAssembliesNativeSourceFiles/>`
MSBuild task, it appears the `ContainsKey()` check is not using the
correct key for the dictionary.

I fixed this issue and added a `LogDebugMessage()` call, so we can
figure out what is happening upstream in dotnet/maui.
  • Loading branch information
jonathanpeppers committed Jun 21, 2021
1 parent ee49249 commit fc74854
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -47,7 +47,9 @@ void GenerateCompressedAssemblySources ()
continue;
}

if (assemblies.ContainsKey (assembly.ItemSpec)) {
var assemblyKey = CompressedAssemblyInfo.GetDictionaryKey (assembly);
if (assemblies.ContainsKey (assemblyKey)) {
Log.LogDebugMessage ($"Skipping duplicate assembly: {assembly.ItemSpec}");
continue;
}

Expand All @@ -57,8 +59,7 @@ void GenerateCompressedAssemblySources ()
continue;
}

assemblies.Add (CompressedAssemblyInfo.GetDictionaryKey (assembly),
new CompressedAssemblyInfo (checked((uint)fi.Length)));
assemblies.Add (assemblyKey, new CompressedAssemblyInfo (checked((uint)fi.Length)));
}

uint index = 0;
Expand Down

0 comments on commit fc74854

Please sign in to comment.