Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Could not load assembly System.Threading.Tasks.Extensions

GerryHGerryH USMember ✭✭✭

Everything was fine. Then can no longer build. I was trying to add plugin.multilingual to my project when this error came up. Now nothing I do can fix it. I removed the plugin, went back to the previously checked in version of my app, rebooted my PC (getting desperate), deleted the packages folder... Nothing works, project is just dead now.

Error       Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Threading.Tasks.Extensions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Perhaps it doesn't exist in the Mono for Android profile?

File name: 'System.Threading.Tasks.Extensions.dll'

   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
   at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver)   TyreSense.Android           

Version 4.1.1.0 doesn't even seem to exist on the nuget page for System.Threading.Tasks.Extensions. Cannot find any reference to that version in my project either. Any ideas how to fix this?

I have the very latest VS 2017 professional as of today.

Best Answers

  • GerryHGerryH USMember ✭✭✭
    Accepted Answer

    I manually restored System.Threading.Tasks.Extensions in the project files and packages.config files, and can now build again. There seems to be a bug in the nuget package manager.

Answers

  • GerryHGerryH USMember ✭✭✭
    edited August 2018

    I have gone back through my git checkins, 4 checkins back it seems a nuget package update actually removed System.Threading.Tasks.Extensions from the project file. But adding it back doesn't fix the 'cannot load' problem.

    The annoying part is I rebuilt and tested all these checkins, why sometime later the problem appears is a mystery.

  • GerryHGerryH USMember ✭✭✭
    Accepted Answer

    I manually restored System.Threading.Tasks.Extensions in the project files and packages.config files, and can now build again. There seems to be a bug in the nuget package manager.

  • minafaw3minafaw3 Member ✭✭

    I have the same issue, I tried to restore nuget manually but it doesn't work
    I tried also to install from nuget but I cant find this specific version 4.1.1.0
    any on

    www. nuget .org / packages / System.Threading.Tasks.Extensions/

  • adyshimonyadyshimony USMember ✭✭

    I am getting crazy from this error. I can't find who is using this lib version for android:

    Could not load assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

    There is not such version for android.
    https://www.nuget.org/packages/System.Threading.Tasks.Extensions/

  • adyshimonyadyshimony USMember ✭✭

    @minafaw3 said:
    I have the same issue, I tried to restore nuget manually but it doesn't work
    I tried also to install from nuget but I cant find this specific version 4.1.1.0
    any on

    www. nuget .org / packages / System.Threading.Tasks.Extensions/

    Did you find how to solved it?

  • The root cause is in package System.Threading.Tasks.Extensions there are no dll's in the targets other than NetStandard2.0
    A temporary resolution for this could be to add the following to your project file manually
    <ItemGroup> <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" /> <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2"/> </ItemGroup> <ItemGroup> <Reference Include="System.Threading.Tasks.Extensions"> <HintPath>$(UserProfile)\.nuget\packages\system.threading.tasks.extensions\4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath> </Reference> </ItemGroup>

  • GerryHGerryH USMember ✭✭✭

    Wouldn't it be nice if Xamarin would fix this bug one day? It's back for me.

  • GerryHGerryH USMember ✭✭✭

    Thanks Brendan, I can link once again.

    Link from github says to add

    <ItemGroup>
        <PackageReference Include="System.Reactive" Version="4.1.1" />
        <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2"/>
      </ItemGroup>
      <ItemGroup>
        <Reference Include="System.Threading.Tasks.Extensions">
          <HintPath>$(UserProfile)\.nuget\packages\system.threading.tasks.extensions\4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
        </Reference>
      </ItemGroup>
    

    to your (in my case Android) project file

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    A year later and this is still a problem.
    If I install System.Threading.Tasks.Extensions 4.5.3 there is no reference.
    If I install version 4.5.0 as mentioned on StackOverflow, then compile fails with Java.exe exited with code 2
    https://stackoverflow.com/questions/52747838/xamarin-can-not-resolve-reference-system-threading-tasks-extensions-referen

    Now I guess I'll try hand editing the android project file. Maybe update the above trick for 4.5.3.

    Back to the old world of - Play with it and d!ck around for a day until it magically comes back to life. Its the programmer version of "giggle the handle" when your toilet is running.

    What a PITA. How many years has this been going on that after any/every update something fails to compile.
    All I did was update the Xamarin.Forms package from some minor fourth place build number increment and suddenly my app won't compile.
    ## :s ##

  • ampleeamplee Member

    FYI, I have to use Visual Studio 2017 an older version because Visual Studio 2019 doesn't work for me since some updated last year.

    Chris Pulman's solution worked for me. After I did that though, I had to delete my Temp storage under: C:\Users\name\AppData\Local\Xamarin.

    Also, I had to delete the files in the respective obj/ bin folders, this seems to be a regular occurence I bump into with Xamarin. Thanks for the solution!

Sign In or Register to comment.