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> 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".
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)
It is rather a Microsoft.Build issue. At least from xamarin-android developers' perspective, we have no control over how NuGet package dependencies are resolved, how *.csproj is modified, or how MSBuild resolves those dependencies within itself (we offer framework assemblies along with MSBuild manner, no chance to control nuget side of things).
The project references in *.csproj after adding Newtonsoft.Json package is simple:
<Reference Include="Microsoft.CSharp" />
It is msbuild's responsibility to appropriately resolve the reference to the appropriate assembly. Actually msbuild is doing almost the right job by (1) warning the possibility that the app may not be actually running the assembly the developer expects, and (2) choosing the "right" one in Xamarin.Android framework.
/devel/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(5,5): Warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. (MSB3277) (HelloWorld)
As long as I tested by myself, the reference to Newtonsoft.Json.dll is resolved to the one in lib/netstandard1.3. NuGet would also have no idea on which of netstandard1.3 or a PCL profile is "better" to resolve, so it's unlikely NuGet's fault. (Also, not of VS either.)
I cannot think of any solution for this situation (maybe MSBuild devs would), but it's worth noting that the result is just warning, not error.
Following the link to the original bug, the fix is to remove the explicit reference to the Microsoft.CSharp 2.0.5. This will allow MSBuild to include the correct net standard version which NewtonSoft is referencing.
I don't think this is a Xamarin.Android bug, but more like a feature of MSBuild as @atsushieno pointed out.
How can we explicitly remove the reference Microsoft.Csharp refence which is referenced inside Xamarin.iOS?

Thank you I'll try to do that.
@stijnvanbossuyt I have no idea, probably best to open and issue for the iOS team.
The fix is to remove the Microsoft.CSharp 2.0.5 and allow the one from Nuget to be used.
Don't dare to remove the right one (2.0.5). Let msbuild pick the right one. Warning is much better than possible run-time failures due to implementation mismatch.
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
Repair Visual Studio worked for me. I tried everything but nothing worked. I hope this can help someone. Best Regards.
Seems to be also an issue with dapper now as well if you have it in a project.
I am also getting this warning in our project with a message
"Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed". I tried lots of things from the web but nothing seems to be working.
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.
Is there a solution for this?
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
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 Studio2019PreviewCommunityMSBuildXamarinAndroidXamarin.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!
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
Most helpful comment
Is there a solution for this?