Search code examples
c#xamarinxamarin.androidzxing

Cant Build my App in Release mode


My App works fine in debug mode, but if i want to build it in release i get the following error:

Fehler  1   Unerwarteter Fehler bei der LinkAssemblies-Aufgabe.
Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'System.Void Xamarin.Forms.Element::set_AutomationId(System.String)' (defined in assembly 'ZXing.Net.Mobile.Forms, Version=2.1.47.0, Culture=neutral, PublicKeyToken=null') with scope 'Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Xamarin.Forms.Element::set_AutomationId(System.String)
   bei Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
   bei Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
   bei Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
   bei Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
   bei Mono.Linker.Steps.MarkStep.ProcessQueue()
   bei Mono.Linker.Steps.MarkStep.Process()
   bei Mono.Linker.Steps.MarkStep.Process(LinkContext context)
   bei MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
   bei Mono.Linker.Pipeline.Process(LinkContext context)
   bei MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
   bei Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
   --- Ende der internen Ausnahmestapelüberwachung ---
   bei Java.Interop.Tools.Diagnostics.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args)
   bei Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
   bei Xamarin.Android.Tasks.LinkAssemblies.Execute()
   bei Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   bei Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()    Euroscola_App1

This problem exists since today, i dont know if the reason is that i downloaded a newer Xamarin version or because i have installed the ZXing Package.


Solution

  • When the scope is different from the defining assembly, it usually means that the type is forwarded.

    You have the application Linker enabled in your Xamarin.Android application project and there is a mismatch in versions between forwarded types in Xamarin.Forms and ZXing.Net.Mobile.Forms. Basically ZXing.Net.Mobile.Forms was compiled against an older version of Forms then you currently are using in your project and is a really common issue if the assembly contains C# extensions.

    Two options, disable linking for the entire application or disable linking for just the Zing assembly:

    To disable linking for just that one assembly, edit your Android application project (.csproj) and add the following < AndroidLinkSkip>:

    <PropertyGroup>
        <AndroidLinkSkip>ZXing.Net.Mobile.Forms</AndroidLinkSkip>
    </PropertyGroup>
    

    Ref: Xamarin Android Linking: AndroidLinkSkip