android: Microsoft.CSharp conflict

Hi,

I’m facing Microsoft.CSharp conflict due to Newtonsoft.Json.10.0.3. I found this https://bugzilla.xamarin.com/show_bug.cgi?id=59600 Here is the build log:

2> "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
2> References which depend on "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll].
2> C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll
2> Project file item includes which caused reference "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll".
2> Microsoft.CSharp
2> References which depend on "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [].
2> C:\Users\mml\Development\test_app\packages\Newtonsoft.Json.10.0.3\lib\netstandard1.3\Newtonsoft.Json.dll
2> Project file item includes which caused reference "C:\Users\mml\Development\test_app\packages\Newtonsoft.Json.10.0.3\lib\netstandard1.3\Newtonsoft.Json.dll".
2> C:\Users\mml\Development\test_app\tes_app\bin\Debug\netstandard1.6\test_app.dll
2> Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL

Is there a way to fix this?

(related Newtonsoft.Json issue)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 7
  • Comments: 24 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Is there a solution for this?

I am also seeing this same behavior with the newest drop of 16.9. I added Mapster to my project and now I get these errors. I cannot find any explicit reference to the 2.0.5 version of Microsoft.CSharp

Ok here are the acutal steps to reproduce it:

Using Visual Studio 2019 Version 16.10.0 Preview 2.1

Create a Xamarin Forms 5 Project (with android and ios, type flyout in my case) (I have installed the Maui Preview 3 on my PC but think that has no influence?)

Add to the Shared Net Standard 2.1 Project:

Add NuGetPackage Microsoft.Identity.Client 4.30.0 Add NuGetPackage Microsoft.Graph 3.30.0

Build the android project - the error should appear. If not I can upload sample project.

As suggested here, adding the references directory to the android project also didn’t solve the problem https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2593

Solving Attept:

I spend again at least half a day on this and saw @dellis1972 answer where he referens to https://xamarin.github.io/bugzilla-archives/59/59600/bug.html

Where it is asked and recommended to remove the 2.0.5 Reference by Xamarin and just let 4.0 override. Which microsoft responds is save.

Sorry I overlooked the answer @dellis1972 could you provide maybe a more detailed answer for this problem Currently I don’t find where I can remove the reference to net 2.0.5

Or can somebody else maybe help me how to remove this dependency?

Inside the Android csproj is the line

<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />

Just deleting this line leads to a Rebuild Error

Latter line references at my Maschine C:\Program Files (x86)\Microsoft Visual Studio\2019\PreviewCommunity\MSBuild\Xamarin\Android\Xamarin.Android.CSharp.targets

But so far I have nto reached the point where Microsoft.CSharp 4.0.0 was referenced.

Thank you for everybody in assitance in this problem!

Yeah, same here. None of the options this or related issues worked.

Same issue with Microsoft.Graph -

Recently upgraded to xamarin.forms 5.0 and upgraded Microsoft Graph and now I cannot compile anymore…

Latest Version 3.21.0 uses net framework net standard 2.0 and 4.6.1 but all Versions which start with 1…* still use 4.5 and net standard 1.3, Microsoft graph 1.15 still uses netstandard 1.1 but currently I cannot compile with any of the version

Is there any workarround yet? tried removing the andorid Csharp.targets from the Android project but just cased a warning of a unknown netframework version… When are we moving xamarin finally to netstandard


Warning		Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved.
There was a conflict between "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
    References which depend on "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Microsoft Visual Studio\2019\PreviewCommunity\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll].
        C:\Program Files (x86)\Microsoft Visual Studio\2019\PreviewCommunity\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll
          Project file item includes which caused reference "C:\Program Files (x86)\Microsoft Visual Studio\2019\PreviewCommunity\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll".
            Microsoft.CSharp
    References which depend on "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [].
        C:\Users\micha\.nuget\packages\microsoft.graph\3.21.0\lib\netstandard2.0\Microsoft.Graph.dll
          Project file item includes which caused reference "C:\Users\micha\.nuget\packages\microsoft.graph\3.21.0\lib\netstandard2.0\Microsoft.Graph.dll".
            C:\Users\micha\.nuget\packages\microsoft.graph\3.21.0\lib\netstandard2.0\Microsoft.Graph.dll
            D:\Projects\XXX\XXX\XXX\bin\Debug\netstandard2.0\XXX.dll
        C:\Users\micha\.nuget\packages\microsoft.identity.client\4.24.0\lib\monoandroid10.0\Microsoft.Identity.Client.dll
          Project file item includes which caused reference "C:\Users\micha\.nuget\packages\microsoft.identity.client\4.24.0\lib\monoandroid10.0\Microsoft.Identity.Client.dll".
            C:\Users\micha\.nuget\packages\microsoft.identity.client\4.24.0\lib\monoandroid10.0\Microsoft.Identity.Client.dll
            D:\Projects\XXX\XXX\XXX\bin\Debug\netstandard2.0\XXX.dll	XXX.Android		

as mentioned above, it’s caused by Newtonsoft.Json package referenced in a netstandard 2.0 project.

Fortunately, updating Newtonsoft.Json to the latest version( current is 11.0.1 ) will fix this problem. This is because this version of Newtonsoft.Json package for netstandard 2.0 has no dependency to Microsoft.CSharp

The fix is to remove the Microsoft.CSharp 2.0.5 and allow the one from Nuget to be used.

From what I can see in my project, it seem to be related to the fact that all the Mono.Android.dll files in (default) C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\vxx have their assembly versions 0.0.0.0.

If you have Android v9.0 as target framework and select properties for the Mono.Android in your solution explorer, you will see the Path be to the correct /V9.0/Mono.Android.dll, but during compilation, msbuild will use /V1.0/Mono.Android.dll as reference, and the 1.0 version is referencing Microsoft.CSharp 2.0.5.0 instead of 4.0.0.0.

I’m guessing the build pipeline simply choose the first file it finds due to them all having version number 0.0.0.0 and are considered the same, and thus produces the warning.

That being said, so far I have not seen any bad effects of this, apart from the annoying warning in the error log.

I also have the same for System.Numerics.Vectors and the fix is to target for .net6.0-android in MAUI project to use the new .net 6 dlls.