11
votes

I have a Xamarin.Forms (2.5.1.527436) application using VS2017 (15.7.1) on windows. The android project builds and runs fine under debug. However, when I build under release I get the following error:

Severity Code Description Project File Line Suppression State Error The "LinkAssemblies" task failed unexpectedly. Mono.Linker.MarkException: Error processing method: 'System.Void Xamarin.Forms.Pages.BaseDataSource/d__22::MoveNext()' in assembly: 'Xamarin.Forms.Pages.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Xamarin.Forms.Log::Warning(System.String,System.String) at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference) at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference) at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction) at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body) at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method) at Mono.Linker.Steps.MarkStep.ProcessQueue() --- End of inner exception stack trace --- at Mono.Linker.Steps.MarkStep.ProcessQueue() at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() at Mono.Linker.Steps.MarkStep.Process() at Mono.Linker.Steps.MarkStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() IRMobile.Android C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1812

I am linking "Sdk Assemblies Only", min android version is 5.1 (level 22) and target Android version is 8.1 (Level 27)

Any ideas?

2
Please refer to this. - Robbit
Thanks for the link @JoeLv-MSFT. That led me in the right direction. I found that my issue was an unnecessary NuGet package which apparently was loading the same assembly. Again, thanks! - Mark Erickson

2 Answers

7
votes

In my case after a bunch of research I just

  • Upgraded some nuget packages, in the 3 projects Forms, Android and iOS and this fixed the issue in release mode.

OR

  • Also changing the Linking to None fixed the issue without upgrading the packages but I think it is not recommended.
2
votes

So changing the linking to none and ensuring all the Nuget packages were updated did not work for me. In my case, my android project and been tweaked and changed for close to a year adding and removing nuget packages. Thus I had a large number of Android specific nuget packages in my solution that were not needed. To determine what I could remove,

  1. I created a brand new Xamarin forms project only for Android.
  2. I added all the Nuget Packages from my original solution that were not Android specific.
  3. I ensured the new solution compiled in debug and release mode.
  4. I went back to my original solution and removed all the Nuget packages that existed in that real solution but not in my brand new solution.

The only piece of code I had to change was with regard to my splash screen. In my splash screen activity I have the following

using Android.Support.V7.App;
public class SplashActivity : AppCompatActivity

when I removed the reference to the Android.Support.V7.App library, the AppCompatActivity was not found. To fix this I simply added the following using statement:

using AndroidX.AppCompat.App;

Once I did all of this, the application would compile in release mode ( is still had linking set to none) and run fine.

This is just another option in case the other solutions end up not working for you.