The "LinkAssemblies" task failed unexpectedly

Hi All,
I am building my app on release mode and getting the following error below. This started when i upgraded to xamarin 8.1. I don't know what to do to resolve this. I have looked at this link https://developer.xamarin.com/guides/xamarin-forms/troubleshooting/questions/android-linkassemblies-error/ and it does not work for me. Please any ideas.

Severity Code Description Project File Line Suppression State
Error The "LinkAssemblies" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
at Mono.Linker.TypeReferenceExtensions.d__4.MoveNext()
at Mono.Linker.Steps.TypeMapStep.TryMatchMethod(TypeReference type, MethodDefinition method)
at Mono.Linker.Steps.TypeMapStep.GetBaseMethodInTypeHierarchy(TypeDefinition type, MethodDefinition method)
at Mono.Linker.Steps.TypeMapStep.MapVirtualMethods(TypeDefinition type)
at Mono.Linker.Steps.TypeMapStep.MapType(TypeDefinition type)
at Mono.Linker.Steps.TypeMapStep.ProcessAssembly(AssemblyDefinition assembly)
at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, 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() UTLOConfApp C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1696

Tagged:

Best Answer

  • ValentineAzomValentineAzom ZA ✭✭
    Accepted Answer

    Hi All,

    Thanks for the help so far. I tried every of your suggestions but unfortunately none worked for me. The issue was due the latest android.support.v7 (v26.0.2) i was using in my app. When i downgraded these versions to v25.0.4 all was well and i was able to build the app in release mode.

Answers

  • DarshanJSDarshanJS USMember ✭✭✭✭
    1. In your project properties change the settings of linking to SDK assemblies only.
    2. try by cleaning the solution
    3. Check whether in portable project references any unwanted .iOS files are there
  • CharwakaCharwaka INMember ✭✭✭✭✭

    Hi @ValentineAzom

    Try below My Solutions

    ->Delete all Packages first and restore them once

    c-sharpcorner.com/blogs/the-resolvelibraryprojectimports-task-failed-unexpectedly

  • ValentineAzomValentineAzom ZAMember ✭✭

    @DarshanJS,

    I have tried that and it did not work for me. However will try @Charwaka solution and get back.

    Regards

  • ValentineAzomValentineAzom ZAMember ✭✭
    Accepted Answer

    Hi All,

    Thanks for the help so far. I tried every of your suggestions but unfortunately none worked for me. The issue was due the latest android.support.v7 (v26.0.2) i was using in my app. When i downgraded these versions to v25.0.4 all was well and i was able to build the app in release mode.

  • FilipLarssonFilipLarsson SEMember ✭✭

    I'm having the same issue. I can't downgrade since the packages have circular dependencies. :(

  • CharwakaCharwaka INMember ✭✭✭✭✭

    @FilipLarsson said:
    I'm having the same issue. I can't downgrade since the packages have circular dependencies. :(

    Find the starting package and start downgrade from there

  • FilipLarssonFilipLarsson SEMember ✭✭

    @Charwaka said:

    @FilipLarsson said:
    I'm having the same issue. I can't downgrade since the packages have circular dependencies. :(

    Find the starting package and start downgrade from there

    There is no starting package in a circular dependency. I reverted back in git, but it did not help.
    The problem occured after I updated Visual Studio. I have the same issue on my PC and Mac.

    https://github.com/xamarin/xamarin-android/blob/master/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
    It's the LinkAssemblies here that fails.

    '$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)');$(_AndroidBuildPropertiesCache)" Outputs="$(_AndroidLinkFlag)">

    <CreateProperty
        Condition="'$(AndroidEnableProguard)' == 'True'"
        Value="$(IntermediateOutputPath)proguard\proguard_project_references.cfg">
        <Output TaskParameter="Value" PropertyName="_ProguardProjectConfiguration" />
    </CreateProperty>
    
    <MakeDir Condition="'$(AndroidEnableProguard)' == 'True'" Directories="$(IntermediateOutputPath)proguard" />
    
    <LinkAssemblies
      UseSharedRuntime="$(AndroidUseSharedRuntime)"
      MainAssembly="$(MonoAndroidLinkerInputDir)$(TargetFileName)"
      OutputDirectory="$(MonoAndroidIntermediateAssetsDir)"
      I18nAssemblies="$(MandroidI18n)"
      LinkMode="$(AndroidLinkMode)"
      LinkSkip="$(AndroidLinkSkip)"
      LinkDescriptions="@(LinkDescription)"
      ProguardConfiguration="$(_ProguardProjectConfiguration)"
      EnableProguard="$(AndroidEnableProguard)"
      DumpDependencies="$(LinkerDumpDependencies)"
      ResolvedAssemblies="@(ResolvedAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')"
      HttpClientHandlerType="$(AndroidHttpClientHandlerType)"
      TlsProvider="$(AndroidTlsProvider)" />
    
    <!-- We have to use a flag instead of normal outputs because linking can delete unused assemblies -->
    <Touch Files="$(_AndroidLinkFlag)" AlwaysCreate="true" />
    


  • CharwakaCharwaka INMember ✭✭✭✭✭
    edited December 2017

    Hi @FilipLarsson

    Try below My Solutions

    ->Delete all Packages first and restore them once

    This is the most common error in Xamarin ,so if you are facing ResolveLibraryProjectImports task failed unexpectedly go through the following solutions to fix it

    Solution 1

    Move your Project to Root Directory
    C:\MyProject
    Clean & Rebuild

    Solution 2:

    Make sure there are no spaces in the name of Solution Folder

    Solution 3
    Restart Visual Studio
    Open the Project
    Clean the solution
    Rebuild the solution
    Close solution
    Reopen the project
    Solution 4

    Delete .suo file which in your solution folder for this you need to show all files options (basically this is a hidden file)

    Solution 5

    Exclude and Include Resources Folder in Android Project if you are working on Android Project

    Solution 6

    Edit .csproj File add this property

    True

    Solution 7

    Try excluding and including files which you added recently to project

    Solution 8

    Make sure your Xamarin Forms is up to date

    Solution 9

    Restart Visual Studio in Admin Mode

    Solution 10

    Cloase Visual Studio ->Delete Packages Folder Completely from solution(open through FileExplorer) and rebuild

    Solution 11

    Try to Downgrade Android Support Packages and Rebuild

    Common Solutions

    Delete and Add References which you find suspicious (due to dependency), Delete all the bin and obj folders from your project directories.

  • FilipLarssonFilipLarsson SEMember ✭✭

    @Charwaka said:
    Hi @FilipLarsson

    Try below My Solutions

    ->Delete all Packages first and restore them once

    I deleted all packages in the file exporer, but still getting the same error.

  • CharwakaCharwaka INMember ✭✭✭✭✭

    @FilipLarsson said:

    @Charwaka said:
    Hi @FilipLarsson

    Try below My Solutions

    ->Delete all Packages first and restore them once

    I deleted all packages in the file exporer, but still getting the same error.

    did you tried all solutions.???

  • FilipLarssonFilipLarsson SEMember ✭✭

    @Charwaka said:

    @FilipLarsson said:

    @Charwaka said:
    Hi @FilipLarsson

    Try below My Solutions

    ->Delete all Packages first and restore them once

    I deleted all packages in the file exporer, but still getting the same error.

    did you tried all solutions.???

    Yes I have tried all now. Still the same error. :( . Your post describes this error: ResolveLibraryProjectImports. We had the issue with LinkAssemblies.

    Xamarin is pretty good when everything works, but not otherwise...

  • mca_lalitmca_lalit Member

    @FilipLarsson, Can you please let us know if you are able to resolve that issue. I am also stuck with same issue, can you please guide me to resolve it.

  • FilipLarssonFilipLarsson SEMember ✭✭

    @mca_lalit said:
    @FilipLarsson, Can you please let us know if you are able to resolve that issue. I am also stuck with same issue, can you please guide me to resolve it.

    @mca_lalit said:
    @FilipLarsson, Can you please let us know if you are able to resolve that issue. I am also stuck with same issue, can you please guide me to resolve it.

    https://developercommunity.visualstudio.com/content/problem/175090/the-linkassemblies-task-failed-unexpectedly-with-v.html?childToView=180144#comment-180144

    Yes now it seems to work. I had to uninstall Visual Studio 15.5.2 and install 15.4.5

  • OoiKengSiangOoiKengSiang MYMember ✭✭

    Same problem still happen in 15.5.5 as well. The only solution found and tested to be working correctly is to revert back to 15.4.5 as mention by others.

    Below are the output error when compile in Release mode.

    error MSB4018: The "LinkAssemblies" task failed unexpectedly.
    error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.
    error MSB4018: at Mono.Linker.TypeReferenceExtensions.d__4.MoveNext()
    error MSB4018: at Mono.Linker.Steps.TypeMapStep.TryMatchMethod(TypeReference type, MethodDefinition method)
    error MSB4018: at Mono.Linker.Steps.TypeMapStep.GetBaseMethodInTypeHierarchy(TypeDefinition type, MethodDefinition method)
    error MSB4018: at Mono.Linker.Steps.TypeMapStep.MapVirtualMethods(TypeDefinition type)
    error MSB4018: at Mono.Linker.Steps.TypeMapStep.MapType(TypeDefinition type)
    error MSB4018: at Mono.Linker.Steps.TypeMapStep.ProcessAssembly(AssemblyDefinition assembly)
    error MSB4018: at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
    error MSB4018: at Mono.Linker.Pipeline.Process(LinkContext context)
    error MSB4018: at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
    error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute()
    error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

  • @ValentineAzom said:
    Hi All,

    Thanks for the help so far. I tried every of your suggestions but unfortunately none worked for me. The issue was due the latest android.support.v7 (v26.0.2) i was using in my app. When i downgraded these versions to v25.0.4 all was well and i was able to build the app in release mode.

    Thank you! Your answer saved me!

  • SergeyIvanov.9607SergeyIvanov.9607 USMember ✭✭

    Maybe this would help somebody
    In my case this error was caused by incorrectly referenced assembly - Droid project referenced iOS library and this was causing the error. Expanding the error message and reading it carefully helped - before the stack trace was the name of troublesome assembly - Camarin.iOS.dll:

    Mono.Linker.MarkException: Error processing method: 'System.Void ObjCRuntime.Runtime::set_UseAutoreleasePoolInThreadPool(System.Boolean)' in assembly: 'Xamarin.iOS.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void System.Threading._ThreadPoolWaitCallback::SetDispatcher(System.Func2<System.Func1<System.Boolean>,System.Boolean>)

  • JassimRahmaJassimRahma USMember ✭✭✭✭

    I am having the same problem even after following up this article:

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/troubleshooting/questions/android-linkassemblies-error

    this is the error:

    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(5,5): Error MSB4018: The "LinkAssemblies" task failed unexpectedly.
    Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'Android.Support.V7.App.NotificationCompat/MediaStyle' (defined in assembly 'Plugin.MediaManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') with scope 'Xamarin.Android.Support.v7.AppCompat, Version=1.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 Android.Support.V7.App.NotificationCompat/MediaStyle
    at Mono.Linker.Steps.MarkStep.HandleUnresolvedType (Mono.Cecil.TypeReference reference) [0x00013] in :0
    at Mono.Linker.Steps.MarkStep.MarkType (Mono.Cecil.TypeReference reference) [0x0002d] in :0
    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType (Mono.Cecil.TypeReference reference) [0x00000] in :0
    at Mono.Linker.Steps.MarkStep.MarkField (Mono.Cecil.FieldReference reference) [0x0004a] in :0
    at Mono.Linker.Steps.MarkStep.InitializeFields (Mono.Cecil.TypeDefinition type) [0x00024] in :0
    at Mono.Linker.Steps.MarkStep.InitializeType (Mono.Cecil.TypeDefinition type) [0x0005d] in :0
    at Mono.Linker.Steps.MarkStep.InitializeAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x0002f] in :0
    at Mono.Linker.Steps.MarkStep.Initialize () [0x00014] in :0
    at Mono.Linker.Steps.MarkStep.Process (Mono.Linker.LinkContext context) [0x00007] in :0
    at MonoDroid.Tuner.MonoDroidMarkStep.Process (Mono.Linker.LinkContext context) [0x0000b] in :0
    at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x0001c] in :0
    at MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in :0
    at MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options, Mono.Linker.ILogger logger, Mono.Linker.LinkContext& context) [0x00071] in :0
    at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x002d4] in :0
    --- End of inner exception stack trace ---
    at Java.Interop.Tools.Diagnostics.Diagnostic.Error (System.Int32 code, System.Exception innerException, System.String message, System.Object[] args) [0x00000] in /Users/builder/data/lanes/6090/a8a3b0ec/source/monodroid/external/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Diagnostics/Java.Interop.Tools.Diagnostics/Diagnostic.cs:165
    at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x004b5] in :0
    at Xamarin.Android.Tasks.LinkAssemblies.Execute () [0x0021f] in :0
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in //src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:631
    at Microsoft.Build.BackEnd.TaskBuilder+d__26.MoveNext () [0x00212] in /
    /src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:787 (MSB4018) (Jafaria.Droid)

    Kindly help..

  • BenGunBenGun Member

    VS 2017 15.8.5
    I just had to close vs and restart again to fix the problem.

  • KayKuoKayKuo Member ✭✭✭

    I closed the problem and restarted the VS to solve the problem.

  • DevanathanDevanathan Member ✭✭
    edited April 16

    I am having the same problem

    Severity Code Description Project File Line Suppression State
    Error The "LinkAssemblies" task failed unexpectedly.
    Mono.Linker.Steps.XmlResolutionException: Failed to process XML description: ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Prism.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Prism.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
    at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    at Mono.Linker.AssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)
    --- End of inner exception stack trace ---
    at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)
    at Mono.Linker.Steps.ResolveFromXmlStep.ProcessAssemblies(LinkContext context, XPathNodeIterator iterator)
    at Mono.Linker.Steps.ResolveFromXmlStep.Process()
    --- End of inner exception stack trace ---
    at Mono.Linker.Steps.ResolveFromXmlStep.Process()
    at Mono.Linker.Steps.BaseStep.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()

    Kindly help

  • DannybangaDannybanga Member ✭✭

    Close your solution, close your VS 2017, re-open your project, rebuild and deploy. That's all you got to do.

    gbammmm! error solved.

Sign In or Register to comment.