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

Viewed 245

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

2 Answers

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

Had the same problem, working on debug, this exception on release. I solved it by: Clean Maui solution -> delete bin and obj -> Close Visual Studio -> Rebuild -> Working

Hope this helps if you didn't try

Related