Skip to content

Conflicting types with mono + nugets + new .net core types #5687

Closed

Description

@mattleibow

Steps to Reproduce

  1. Install Mono 5.16 along with XM that supports it (XM 5.2 for example) edited
  2. Clone/download this repo: https://github.com/mattleibow/ModernMacMayhem
  3. Build with mono 5.16 == success
  4. Build with mono 5.18 == fail

Expected Behavior

Always succeed

Actual Behavior

Fails on mono 5.18

Environment

https://gist.github.com/mattleibow/2f16d6903e1d8a6aa2d0fe246b531d6c

Build Logs

MayhemTests.cs(10,23): error CS0433: The type 'ReadOnlySpan<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'

https://gist.github.com/mattleibow/e1a3fd590d4931788f7244381f45b54c

Example Project (If Possible)

https://github.com/mattleibow/ModernMacMayhem

VS bug #917895

Activity

  1. mattleibow commented on Feb 28, 2019

    @mattleibow
    MemberAuthor

    I ran this same test for iOS, and I got this warning (same on android):

    /Library/Frameworks/Mono.framework/Versions/5.18.0/lib/mono/xbuild/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.ConflictResolution.targets(33,5): message NETSDK1041: Encountered conflict between 'Reference:/Users/matthew/.nuget/packages/system.buffers/4.4.0/ref/netstandard2.0/System.Buffers.dll' and 'Platform:System.Buffers.dll'.  NETSDK1033: Choosing 'Platform:System.Buffers.dll' because AssemblyVersion '4.0.99.0' is greater than '4.0.2.0'. [/Users/matthew/Projects/ModernMacMayhem/tfk/tfk.csproj]
    /Library/Frameworks/Mono.framework/Versions/5.18.0/lib/mono/xbuild/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.ConflictResolution.targets(33,5): message NETSDK1041: Encountered conflict between 'Reference:/Users/matthew/.nuget/packages/system.memory/4.5.2/lib/netstandard2.0/System.Memory.dll' and 'Platform:System.Memory.dll'.  NETSDK1033: Choosing 'Platform:System.Memory.dll' because AssemblyVersion '4.0.99.0' is greater than '4.0.1.0'. [/Users/matthew/Projects/ModernMacMayhem/tfk/tfk.csproj]
    /Library/Frameworks/Mono.framework/Versions/5.18.0/lib/mono/xbuild/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.ConflictResolution.targets(33,5): message NETSDK1041: Encountered conflict between 'Platform:System.Buffers.dll' and 'CopyLocal:/Users/matthew/.nuget/packages/system.buffers/4.4.0/lib/netstandard2.0/System.Buffers.dll'.  NETSDK1033: Choosing 'Platform:System.Buffers.dll' because AssemblyVersion '4.0.99.0' is greater than '4.0.2.0'. [/Users/matthew/Projects/ModernMacMayhem/tfk/tfk.csproj]
    /Library/Frameworks/Mono.framework/Versions/5.18.0/lib/mono/xbuild/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.ConflictResolution.targets(33,5): message NETSDK1041: Encountered conflict between 'Platform:System.Memory.dll' and 'CopyLocal:/Users/matthew/.nuget/packages/system.memory/4.5.2/lib/netstandard2.0/System.Memory.dll'.  NETSDK1033: Choosing 'Platform:System.Memory.dll' because AssemblyVersion '4.0.99.0' is greater than '4.0.1.0'. [/Users/matthew/Projects/ModernMacMayhem/tfk/tfk.csproj]
    
  2. added
    bugIf an issue is a bug or a pull request a bug fix
    macOSIssues affecting macOS
    vs-sync*Only use when triaging (not before)* Syncs this bug with VSTS
    regressionThe issue or pull request is a regression
    on Feb 28, 2019
  3. added this to the Future milestone on Mar 4, 2019
  4. softlion commented on Jun 13, 2019

    @softlion

    I need a workaround for this one that bogus me for a full week, i need to release the app to appstore now.
    I fallback using VSMac which does not have this issue (xamarin.ios 12.8 and 12.10).

    Using Windows VS2019 (xamarin.ios 12.10) it fails with the same error.
    Using Windows VS2019preview (xamarin.ios 12.14) it fails with the same error.
    Using Windows VS2017 (xamarin.ios 12.6) it succeeds.
    Using Mac VS2019 stable (xamarin.ios 12.8) it succeeds.

    6>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190.
     
    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'
     
    
  5. mattleibow commented on Jun 25, 2019

    @mattleibow
    MemberAuthor

    I just realized this gets worse. If I am building on 5.16 and use the NuGet, then I now get a dependency on that NuGet. In order to use this assembly, I cannot be on 5.18.

    If I build on 5.18, then I don't use the NuGet. But now there is a whole type missing form the world.

  6. added a commit that references this issue on Jun 25, 2019
  7. mattleibow commented on Jun 25, 2019

    @mattleibow
    MemberAuthor

    I see Span<T> and ReadOnlySpan<T> technically exists in Android, but is marked internal.

  8. chamons commented on Jun 26, 2019

    @chamons
    Contributor

    On latest stable the build passes - https://gist.github.com/chamons/9bfc63518a7917e67ad864c6fb98ee4a

    Mono - 5.18.1.28
    XM - 5.10.0.157

    And preview - https://gist.github.com/chamons/f3198be18446b539299dea580a482eb0

    mono 6.0.0.296
    XM - 5.14.0.91

    I know this was filed months ago and overlooked (apologies!). Could you try to reproduce on a more recent set of builds?

  9. added
    need-infoWaiting for more information before the bug can be investigated
    on Jun 26, 2019
  10. mattleibow commented on Jun 26, 2019

    @mattleibow
    MemberAuthor

    That is the point. It does not work with old mono. mono 5.16. So, if a user is building with an older version of Xamarin, then he will get type not found.

  11. changed the title [-]Conflicting types with new mono + nugets + new .net core types[/-] [+]Older XM/Mono have conflicting types with new mono + nugets + new .net core types[/+] on Jun 28, 2019
  12. 9 remaining items

  13. removed this from the d16-2 milestone on Jul 11, 2019
  14. added this to the Future milestone on Jul 16, 2019
  15. softlion commented on Aug 29, 2019

    @softlion

    This problem is back, for iOS only.

  16. softlion commented on Aug 29, 2019

    @softlion
    1>          Considered "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Memory.dll",
    1>  			but its name "System.Memory, Version=4.0.99.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"
    1>  			didn't match the expected name "System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". (TaskId:29)
    
  17. softlion commented on Aug 29, 2019

    @softlion

    It is caused by the system.reactive nuget

  18. softlion commented on Aug 29, 2019

    @softlion

    Workaround: add the "System.Memory" nuget version 4.5.0 to the ios project. All other versions of System.Memory trigger the issue.

  19. mattleibow commented on Nov 26, 2019

    @mattleibow
    MemberAuthor

    In the projects that have this issue, I add:

    <PackageReference Include="System.Memory" Version="4.5.3" IncludeAssets="None" />

    Note the IncludeAssets="None"

    Or as @softlion says, use version 4.5.0: #5687 (comment)

  20. changed the title [-]Older XM/Mono have conflicting types with new mono + nugets + new .net core types[/-] [+]Conflicting types with mono + nugets + new .net core types[/+] on Nov 26, 2019
  21. spouliot commented on Nov 28, 2019

    @spouliot
    Contributor

    This is not related to XM itself, it's a compiler error.

    What happens is that the type ReadOnlySpan<T> [1] was added in .netstandard 2.1, which mono gradually added support over the last year (and it should be in full compliance in d16-3 / mono 6.4 [2]). If not then it's a (mono) bug.

    Basically mono added ReadOnlySpan<T> in 5.18, which means external code (e.g. nugets) providing their own versions will conflict (and the compiler will produce an error like above).

    Mono 5.16 did not have the type, so it behaved more like netstandard 2.0, and the external version of the type was fine (i.e. no compiler error).

    If you use an earlier .netstandard (the above logs shows 2.0) then some nugets, that wants/needs the feature, might be including the type which can cause conflict. Updating those nugets to newer versions that target netstandard 2.1 should fix the issue.

    Hopefully this situation will resolve itself with .net 5 since the everything will be closely sync'ed. In the mean time updating your mono might require you to update some of your nugets too.

    [1] https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1
    [2] mono/mono#11430

  22. ericstj commented on Jan 10, 2020

    @ericstj
    Member

    For Xamarin to correctly implement .NETStandard 2.1 it needs to supersede all libraries which are absorbed into .NETStandard 2.1, same as it did with System.Runtime et-al for .NETStandard 2.0.

    This will be a problem for all of the libraries which were absorbed into .NETStandard2.1. See dotnet/standard#1063

    @marek-safar it looks like you have these libraries but your build isn't preferring them over the nuget packages. We could go back and retro-actively service all the nuget packages to add placeholders, but that's a bad fix since it requires everyone to update.

    I think Xamarin should update their build tooling to perfer their own copy of these. The way this works for .NETCore is through the .NET SDK's conflict resolution which prefers the newer framework assembly.

  23. marek-safar commented on Jan 13, 2020

    @marek-safar
    Contributor

    I think Xamarin should update their build tooling to perfer their own copy of these

    I agree and that's what we did for assemblies which Xamarin needs to prefer over NuGet versions. As you can see from the log above the assembly actually exists in Xamarin.iOS and I believe this used to work.

    1>          Considered "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Memory.dll",
    1>  			but its name "System.Memory, Version=4.0.99.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"
    1>  			didn't match the expected name "System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". (TaskId:29)
    

    We need to investigate why the 4.0.99.0 is not the prefered version in msbuild resolution logic anymore.

    /cc @radical who did the original testing IIRC

  24. juwens commented on Dec 16, 2021

    @juwens

    Greetings from end of 2021.
    though the ticket was closed two years ago, it's still a problem in a new xamarin-ios project with netstandard 2.0 nuget released from MS two days ago. 🤨

    image

    /Users/jjaehrig/Projects/OnnxRuntimeMissingMethodException/OnnxRuntimeMissingMethodException/Main.cs(32,32): 
    Error CS0433: The type 'Memory<T>' exists in both 
    'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 
    'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' (CS0433) (OnnxRuntimeMissingMethodException)
    
  25. ghost locked as resolved and limited conversation to collaborators on May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIf an issue is a bug or a pull request a bug fixmacOSIssues affecting macOSvs-sync*Only use when triaging (not before)* Syncs this bug with VSTS

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions