Xamarin-macios: Build error with Microsoft.Extensions.Logging + Memory<T> (vs2019 only)

Created on 24 Jun 2019  路  8Comments  路  Source: xamarin/xamarin-macios

Steps to reproduce:

  • create a new ios project using VS2019
  • add nuget "Microsoft.Extensions.Logging"
  • in appdelegate's FinishedLaunching, add:
    var tcs = new TaskCompletionSource<Memory<byte>>();

Builld.

Expected: builds fine

Result: fails to build

Note: same project builds fine using VS Mac.

1>  C:\Users\toto\source\repos\App1\AppDelegate.cs(26,48,26,60): error CS0433: The type 'Memory<T>' exists in both 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

Build Logs:

buildlogs.txt

Version info:

versionvs.txt

VS bug #942454

bug external-xamarin-vs

All 8 comments

System.Memory, Version=4.0.1.0 is not what is shipped with the Xamarin.iOS SDK. My _guess_ is that it resolve differently on Windows (than on the Mac - which I confirmed works).

This is caused by the same issue I looked at here https://github.com/dotnet/runtime/issues/1460, and discussed here https://github.com/xamarin/xamarin-macios/issues/5687. To workaround you can exclude the System.Memory that came from the package.

If the project is using packages.config, then delete the <Reference from the Csproj. If the project is using PackageReference <PackageReference Include="System.Memory" Version="4.5.3" IncludeAssets="None" />

@ericstj I never imported System.Memory. It seems to be automatically included as a dependency of an existing nuget package. But there is no way to find out which package is including this old package.

Right, even if brought in as a transitive dependency this workaround should help. If the project uses packages.config, just delete the System.Memory reference from the CSProj. If the project uses PackageReference, then you can add a System.Memory reference and set IncludeAssets="none" (which will supersede any transitive dependency).

you mean that adding the latest version of System.Memory with IncludeAssets="none" should fix the issue ?

Yep, you just need to prevent the package from winning. Xamarin SDK's copy needs to win over the package copy, so do whatever you need to do to prevent the package copy from making it in the app.

Note: I just ran into this same issue and to fix it I _also_ had to do git clean -xdf to remove a bunch of now-stale .props and .targets files that were previously restored into obj/ folders.

Thank you @ericstj for the workaround! I spent the better part of a day wondering what was wrong until I decided to do a search and found this issue (and several other related ones).

Was this page helpful?
0 / 5 - 0 ratings