reactive: Cannot compile Xamarin Android project with System.Reactive v4.1.0

Description

The new dependency System.Threading.Tasks.Extensions cannot be fully resolved on Xamarin Android projects. This is not a problem of Rx.NET but I’m leaving this here so other people can see it.

How to reproduce:

  1. Create a Xamarin Android project
  2. Add the System.Reactive nuget package version 4.1.0
  3. Compile and run.

Expected result An application running

Actual result An exception is thrown: Severity Code Description Project File Line Suppression State Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.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, ICollection1 assemblies, AssemblyDefinition assembly, Boolean topLevel) at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) Poi.RxStte

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 19
  • Comments: 71 (17 by maintainers)

Commits related to this issue

Most upvoted comments

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 System.Reactive 4.1.0 and 4.1.1 could be to add the following to your project file manually setting the desired version of System.Reactive as required

<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>

Hope this helps

Downgrading System.Threading.Tasks.Extension from 4.5.1 to 4.4.0 worked for me. Using:

  • System.Reactive 4.1.0 (latest)
  • System.Reactive.Interfaces 4.1.0 (latest)
  • System.Reactive.Linq 4.1.0( latest)
  • System.Reactive.PlatformServices (latest)
  • System.Threading 4.3.0 (latest)
  • System.Threading.Taks 4.3.0 (latest)
  • System.Threading.Tasks.Extensions 4.4.0 (downgraded)

All release versions of VS 2019 (including for Mac) should come with a fixed version of Xamarin.Android now, I think this can be considered solved now.

Sadly, GitHub doesn’t allow marking comments as answers or pinning them, but i’d like to note one more time, that Chris Pulman’s solution works for System.Reactive 4.1.0, 4.1.1 and also 4.1.2. I’m able to compile my ReactiveUI Xamarin.Android application using the setup he suggested (thanks!)

<ItemGroup>
  <PackageReference Include="System.Reactive" Version="4.1.2" />
  <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
  <!-- Other references to packages you need -->
</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>

Put these lines into your .csproj file and it’ll work, no need to rollback to System.Reactive 4.0.x.

@ahmedalejo In-box, at least in the Xamarin context, means that the deployed runtime got the necessary bits already bundled, so that a referenced nuget package may just omit any files for that platform. The System.Threading.Tasks.Extensions nuget in version 4.5.1 assumes the appropriate dlls be present on the Xamarin platform (in-box!), but they aren’t. It’s a bug, it’ll be fixed eventually, until that, downgrade to System.Threading.Tasks.Extensions 4.4.0 which is just fine.

Out of box means the opposite: The nuget has to provide the actual dlls, which is of course the case for most stuff on nuget.

image

Uhu! all day on this bug. Just downgraded System.Reactive to 4.0.0 and i´m good to continue

Thanks for holding this discussion, it helped a lot!

@onovotny could you please enlighten me about In-box and out of box that you mentioned about nuget packages?

It’s almost 2019 and the issue still persists.

I can still see the issue in an Azure DevOps build @danielcweber . My build uses the Xamarin.iOS task on my Xamarin.Forms solution but the error seems to be linked to the Android csproj.

error XA2002: Can not resolve reference: System.Threading.Tasks.Extensions, referenced by System.Reactive. Please add a NuGet package or assembly reference for System.Threading.Tasks.Extensions, or remove the reference to System.Reactive.

My project uses 4.1.5 version of System.Reactive. Downgrading to version 4.0.0 works.

@sushihangover simply use the workaround, reference the 4.4 version in the Android project.

It’s been half a year!!! Can’t believe this issue still exists.

In my case, I use a mac, it is adding below into .csproj file

 <ItemGroup>
   <Reference Include="System.Threading.Tasks.Extensions">
     <HintPath>..\packages\System.Threading.Tasks.Extensions.4.4.0\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
   </Reference>
 </ItemGroup>

@danielcweber: VS for Mac 7.6.7 (build 49) won’t let me have a dependency on System.Threading.Tasks.Extensions 4.4.0, when I have System.Reactive 4.1.0.

I’m working on a Xamarin.Forms app, and the dependency problem is in the Packages for both Android and iOS projects (but no problems in our portable Xamarin projects).

Any suggestions for us Mac users?

@ahmedalejo As pointed out above, there is no need to downgrade Rx to 4.0. It is sufficient to take an excplicit dependency on System.Threading.Tasks.Extensions 4.4.0 in your top project.

What worked for me was keeping System.Threading.Tasks.Extensions upgraded, installing System.Runtime.CompilerServices.Unsafe to all android, ios, and uwp projects, and downgrading System.Reactive to version 4.0.0

According to https://github.com/xamarin/xamarin-android/commit/bf2b59ce6ea13640668dd6385ef287938d2628d7, the fix is included in the following versions of Xamarin.Android:

grafik

From this, I can’t see the fix being included in any version of VS 2017 (15.x). Therefore, please upgrade to VS 2019.

I will close this issue for now. If anybody sees the issue still persisting despite using the latest version of Visual Studio 2019 and Xamarin.Android, leave a note and detailed version information.

@sushihangover simply use the workaround, reference the 4.4 version in the Android project.

Yes, using System.Reactive 4.1.2 and by adding the reference to System.Threading.Tasks.Extensions 4.4.0 it works. Thanks.

I hope this year XD will be a fix for this issue

I am using the Hosted Visual Studio 2019 agent but I don’t know which precise version of Visual Studio 2019 is installed in this Hosted agent and when this version is updated by Microsoft.

It’s still there reactiveui -Version 9.15.1 VS 15.9.11

Severity Code Description Project File Line Suppression State Error Can not resolve reference: System.Threading.Tasks.Extensions, referenced by System.Reactive. Please add a NuGet package or assembly reference for System.Threading.Tasks.Extensions, or remove the reference to System.Reactive.

According to https://docs.microsoft.com/de-de/xamarin/android/release-notes/9/9.2, it is fixed in Xamarin.Android 9.1.103.7 which comes with Visual Studio 2019 Preview 2.

Any other solution than referencing the old 4.4.0 version ? Since 6 months ? Noone uses Reactive in Xamarin ?

As we use CI, so this won’t work.

If you want the most repeatable thing, just add the dlls to your repo and put in a path to the local copy:

james@DESKTOP-5ICP5OV:/mnt/c/Users/james/source/repos/App3$ tree binaries/ binaries/ └── netstandard2.0
├── System.Runtime.CompilerServices.Unsafe.dll
└── System.Threading.Tasks.Extensions.dll

Also, $(UserProfile) is a weird nonstandard windows hack, so you’ll need to add your weird nonstandard Macos hack too -

<ItemGroup>
  <Reference Include="System.Threading.Tasks.Extensions">
    <HintPath>$(UserProfile)$(HOME)\.nuget\packages\system.threading.tasks.extensions\4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
  </Reference>
</ItemGroup>

@godrose this issue is completely external to us and is something with VSfM/Xamarin. Unfortunately there’s little we can do.

/cc @unniravindranathan

Have you tried the latest version of VSfM/Xamarin?

@jonpryor I tried with 15.8 stable:

Can not resolve reference: `System.Threading.Tasks.Extensions`, referenced by `System.Reactive`. Please add a NuGet package or assembly reference for `System.Threading.Tasks.Extensions`, or remove the reference to `System.Reactive`.	App38	C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets

Our error message is a lot better now, this is from the error pad.

What is weird about this, is the System.Reactive NuGet has a dependency on System.Threading.Tasks.Extensions, why isn’t it installed?

When I look at the build log, the NuGet MSBuild task, has outputs:

ResolveNuGetPackageAssets

_ReferencesFromNuGetPackages
    %UserProfile%\.nuget\packages\system.reactive\4.1.0\lib\netstandard2.0\System.Reactive.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = System.Reactive
        NuGetPackageVersion = 4.1.0
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.arch.core.common\1.0.0.1\lib\MonoAndroid80\Xamarin.Android.Arch.Core.Common.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Arch.Core.Common
        NuGetPackageVersion = 1.0.0.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.arch.lifecycle.common\1.0.3.1\lib\MonoAndroid80\Xamarin.Android.Arch.Lifecycle.Common.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Arch.Lifecycle.Common
        NuGetPackageVersion = 1.0.3.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.arch.lifecycle.runtime\1.0.3.1\lib\MonoAndroid80\Xamarin.Android.Arch.Lifecycle.Runtime.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Arch.Lifecycle.Runtime
        NuGetPackageVersion = 1.0.3.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.animated.vector.drawable\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Animated.Vector.Drawable.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Animated.Vector.Drawable
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.annotations\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Annotations.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Annotations
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.compat\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Compat.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Compat
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.core.ui\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Core.UI.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Core.UI
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.core.utils\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Core.Utils.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Core.Utils
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.design\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Design.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Design
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.fragment\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Fragment.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Fragment
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.media.compat\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Media.Compat.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Media.Compat
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.transition\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Transition.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Transition
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.v7.appcompat\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.v7.AppCompat.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.v7.AppCompat
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.v7.recyclerview\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.v7.RecyclerView.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.v7.RecyclerView
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false
    %UserProfile%\.nuget\packages\xamarin.android.support.vector.drawable\27.0.2.1\lib\MonoAndroid81\Xamarin.Android.Support.Vector.Drawable.dll
        NuGetIsFrameworkReference = false
        NuGetPackageId = Xamarin.Android.Support.Vector.Drawable
        NuGetPackageVersion = 27.0.2.1
        NuGetSourceType = Package
        Private = false

@DrQwertySilence when I manually install System.Threading.Tasks.Extensions (Version 4.4.0, not the newest!) it fixes it. Does this work for you?