Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use Dictionary<K,V> to avoid duplicate value exception #7340

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

grendello
Copy link
Contributor

Fixes: #7302
Context: 7117414

When building .NET6 app on .NET7, sometimes the build fails with:

C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.451\tools\Xamarin.Android.Common.targets(1438,3): error XAGJS7004: System.ArgumentException: An item with the same key has already been added.
 at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
 at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
 at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState)
 at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache)
 at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
 at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
 at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

Avoid that by switching the data structure to List<T>, since we no
longer use the Dictionary key for anything.

Fixes: dotnet#7302
Context: dotnet@7117414

When building .NET6 app on .NET7, sometimes the build fails with:

    C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.451\tools\Xamarin.Android.Common.targets(1438,3): error XAGJS7004: System.ArgumentException: An item with the same key has already been added.
     at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
     at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
     at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState)
     at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache)
     at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
     at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
     at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

Avoid that by switching the data structure to `List<T>`, since we no
longer use the Dictionary key for anything.
@jonathanpeppers jonathanpeppers merged commit 840a415 into dotnet:main Sep 6, 2022
@grendello grendello deleted the typemap-duplicate-types branch September 6, 2022 20:23
jonathanpeppers pushed a commit to jonathanpeppers/xamarin-android that referenced this pull request Sep 6, 2022
…7340)

Fixes: dotnet#7302
Context: dotnet@7117414

When building .NET6 app on .NET7, sometimes the build fails with:

    C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.451\tools\Xamarin.Android.Common.targets(1438,3): error XAGJS7004: System.ArgumentException: An item with the same key has already been added.
     at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
     at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
     at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState)
     at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache)
     at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
     at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
     at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

Avoid that by switching the data structure to `List<T>`, since we no
longer use the Dictionary key for anything.
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 6, 2022
* main:
  [FabricBot] Add `possibly-stale` GitHub label for closing old issues (dotnet#7343)
  Don't use Dictionary<K,V> to avoid duplicate value exception (dotnet#7340)
  [One .NET] fix `dotnet run -c Release` (dotnet#7341)
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 6, 2022
* mm-runtime:
  [FabricBot] Add `possibly-stale` GitHub label for closing old issues (dotnet#7343)
  Don't use Dictionary<K,V> to avoid duplicate value exception (dotnet#7340)
  [One .NET] fix `dotnet run -c Release` (dotnet#7341)
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 6, 2022
* mm-cleanup-and-enable:
  [FabricBot] Add `possibly-stale` GitHub label for closing old issues (dotnet#7343)
  Don't use Dictionary<K,V> to avoid duplicate value exception (dotnet#7340)
  [One .NET] fix `dotnet run -c Release` (dotnet#7341)
  Make AOT work (with trimming)
  Fix Debug mode and Release w/o marshal methods
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants