An item with the same key has already been added MAUI C#

Issue

When I try to run my program in release mode, it give this error:

Severity    Code    Description Project File    Line    Suppression State
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 MauiApp1    C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.440\tools\Xamarin.Android.Common.targets   1438    

It is strange because in debug mode it works fine and I can’t find any answer online.
Window snippet

Solution

I solved it by uninstalling .net7, I found on Maui’s github page people with the same problem and I think it will be fixed in the future.

It remains a shame Maui is not yet ready for .net7

Answered By – emilim

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published