Unable to archive Xamarin.Forms app on Visual Studio for Mac - LinkAssemblies task fails

I have a relatively simple Xamarin.Forms app that uses Realm.io for persistence. I can build the app in both release and debug configurations. However, when I attempt to archive the app in order to distribute it, the package creating fails with the following error:

The most relevant bit:

System.ArgumentException: An item with the same key has already been added. Key: ProcessedByFody

And the full trace from the Archive tab:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2105,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. System.ArgumentException: An item with the same key has already been added. Key: ProcessedByFody at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x0015a] in <b814b509d4ad406fb40c6c93e38929e7>:0 at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <b814b509d4ad406fb40c6c93e38929e7>:0 at System.Linq.Enumerable.ToDictionary[TSource,TKey] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x0007d] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:71 at System.Linq.Enumerable.ToDictionary[TSource,TKey] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/mono-x64/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:34 at MonoDroid.Tuner.MarkJavaObjects.GetTypesInModule (Mono.Cecil.ModuleDefinition module) [0x00006] in <fa231dc8d40d45fd86217b6055f9a563>:0 at MonoDroid.Tuner.MarkJavaObjects.FindType (Mono.Cecil.TypeDefinition type, System.String fullname) [0x0001b] in <fa231dc8d40d45fd86217b6055f9a563>:0 at MonoDroid.Tuner.MarkJavaObjects.GetHelperType (Mono.Cecil.TypeDefinition type, System.String suffix) [0x00042] in <fa231dc8d40d45fd86217b6055f9a563>:0 at MonoDroid.Tuner.MarkJavaObjects.PreserveHelperType (Mono.Cecil.TypeDefinition type, System.String suffix) [0x00000] in <fa231dc8d40d45fd86217b6055f9a563>:0 at MonoDroid.Tuner.MarkJavaObjects.PreserveAdapter (Mono.Cecil.TypeDefinition type) [0x00000] in <fa231dc8d40d45fd86217b6055f9a563>:0 at MonoDroid.Tuner.MarkJavaObjects.PreserveJavaObjectImplementation (Mono.Cecil.TypeDefinition type) [0x0000e] in <fa231dc8d40d45fd86217b6055f9a563>:0 at MonoDroid.Tuner.MarkJavaObjects.ProcessType (Mono.Cecil.TypeDefinition type) [0x00009] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Mono.Tuner.SubStepDispatcher.DispatchType (Mono.Cecil.TypeDefinition type) [0x0002d] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Mono.Tuner.SubStepDispatcher.BrowseTypes (System.Collections.ICollection types) [0x00018] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Mono.Tuner.SubStepDispatcher.BrowseAssemblies (System.Collections.Generic.IEnumerable`1[T] assemblies) [0x0003f] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Mono.Tuner.SubStepDispatcher.Process (Mono.Linker.LinkContext context) [0x0000e] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Mono.Linker.Pipeline.ProcessStep (Mono.Linker.LinkContext context, Mono.Linker.Steps.IStep step) [0x0000d] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x0000f] in <fa231dc8d40d45fd86217b6055f9a563>:0 at MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <fa231dc8d40d45fd86217b6055f9a563>:0 at MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options, Mono.Linker.ILogger logger, Mono.Linker.LinkContext& context) [0x00071] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x002d4] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Xamarin.Android.Tasks.LinkAssemblies.Execute () [0x0001b] in <fa231dc8d40d45fd86217b6055f9a563>:0 at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:574 at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002a9] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:805 Done building target "_LinkAssembliesShrink" in project "MyProject.Android.csproj" -- FAILED.

I am using Visual Studio for Mac Enterprise version 8.3.1 (build 18)

My app is using the following Nuget packages:

  • Newtonsoft.Json 12.0.2
  • Realm 4.1.0
  • Xamarin.Android.Support.Core.Utils 28.0.0.3
  • Xamarin.Essentials 1.3.1
  • Xamarin.Forms 4.2.0.848062

Prior to adding Realm to the project I was able to archive the app. Has anyone encountered and (hopefully) solved a similar issue with Realm/Fody/Xamarin before?

Sign In or Register to comment.