Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.CSharp conflict #1261

Closed
Maxima078 opened this issue Feb 1, 2018 · 24 comments
Closed

Microsoft.CSharp conflict #1261

Maxima078 opened this issue Feb 1, 2018 · 24 comments
Assignees

Comments

@Maxima078
Copy link

Maxima078 commented Feb 1, 2018

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)

@atsushieno
Copy link
Contributor

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.

@dellis1972
Copy link
Contributor

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.

@stijnvanbossuyt
Copy link

How can we explicitly remove the reference Microsoft.Csharp refence which is referenced inside Xamarin.iOS?

screen shot 2018-02-06 at 18 04 16

@Maxima078
Copy link
Author

Thank you I'll try to do that.

@dellis1972
Copy link
Contributor

@stijnvanbossuyt I have no idea, probably best to open and issue for the iOS team.

@dellis1972
Copy link
Contributor

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

@atsushieno
Copy link
Contributor

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.

@FrankChen021
Copy link

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

@aliemrecan
Copy link

Repair Visual Studio worked for me. I tried everything but nothing worked. I hope this can help someone. Best Regards.

@davidbuckleyni
Copy link

Seems to be also an issue with dapper now as well if you have it in a project.

@Roshan-Yadav
Copy link

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.

@eriktack
Copy link

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.

collenirwin added a commit to collenirwin/DayTrack that referenced this issue Jul 11, 2020
We've gained a build warning in DayTrack.Android after installing
EFCore.BulkExtensions. After 2 hours of research, I can't seem to
resolve it.
dotnet/android#1261 (comment)
@pmahend1
Copy link

Is there a solution for this?

@MichaelPeter
Copy link

MichaelPeter commented Jan 17, 2021

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		

@MichaelPeter
Copy link

MichaelPeter commented May 3, 2021

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
AzureAD/microsoft-authentication-library-for-dotnet#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!

@scottcollins
Copy link

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

@soroshsabz
Copy link

soroshsabz commented Mar 10, 2022

Please reopen this issue, I think this problem is exist until now

I have the same problem with AutoMapper

Severity	Code	Description	Project	File	Suppression State	Line
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\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll].
        C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\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\Enterprise\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\ssoroosh\.nuget\packages\automapper\8.0.0\lib\netstandard2.0\AutoMapper.dll
          Project file item includes which caused reference "C:\Users\ssoroosh\.nuget\packages\automapper\8.0.0\lib\netstandard2.0\AutoMapper.dll".
            C:\Users\ssoroosh\.nuget\packages\automapper\8.0.0\lib\netstandard2.0\AutoMapper.dll
            D:\Source\Repos\Resa\Resa\Source\DoctorApp\BSN.Resa.DoctorApp.Domain\bin\Debug\netstandard2.0\BSN.Resa.DoctorApp.Domain.dll
            D:\Source\Repos\Resa\Resa\Source\DoctorApp\BSN.Resa.DoctorApp.Data\bin\Debug\netstandard2.0\BSN.Resa.DoctorApp.Data.dll
            D:\Source\Repos\Resa\Resa\Source\DoctorApp\BSN.Resa.DoctorApp\bin\Debug\netstandard2.0\BSN.Resa.DoctorApp.dll	BSN.Resa.DoctorApp.Droid	C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets		2203

@dellis1972 Please reopen this issue

@Manthazar
Copy link

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

@Jerome-Liger
Copy link

Any update ?
The problem is still present for me (VS 2019 (17.1.6) and Xamarin.Forms 5.0.0.2401)
And none of the options this or related issues worked

Conflicts for Microsoft.CSharp :

  • conflict with AutoMapper(V11 & AutoMapper.Extensions.Microsoft.DependencyInjection)
  • conflict with Microsoft.IdentityClient (V4.43.2)
  • conflict with Microsoft.Data.SqlClient (V2.1.2)
  • conflict with efcore.BulkExtensions (V5.4.2)

Conflict_CSharp

Conflict for System.Numeric.Vector :

  • conflict with System.Text.Json (6.0.1)
  • conflict with Microsoft.Extension.Configuration.Json (V5.0.0)
  • conflict with Microsoft.Extension.DependencyModel (V5.0.0)
  • conflict with Microsoft.EntityFrameworkCore.Sqlite.Core (V5.0.16)
  • conflict with Microsoft.Extension.Logging.Console (V5.0.0)
  • conflict with Refit (V6.3.2)
  • conflict with System.Net.Http..Json (6.0.0)

Conflict_Vector

Thanks for reopenning this issue.

@MagicAndre1981
Copy link

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.

@Jerome-Liger
Copy link

Sorry but I can't fix this by migrating to MAUI... and it doesn't fix the problem with Xamarin.Forms(/Android).
MAUI is far to be migrated on production yet...

These bugs are from my projects in production (more than 20) and done with Xamarin.Forms

@MagicAndre1981
Copy link

I know, I see the same for my XF apps. I gave it up on this as the apps work so far

@dellis1972
Copy link
Contributor

@jonpryor can you weigh in on this one? I'm not 100% sure its something we can fix in Legacy Xamarin.Android.

@Manthazar
Copy link

I appreciate that we should be forward looking (into Maui), but please note that for many people migration may only be feasible if third party controls for instance become feature compatible. For instance, people using for instance SyncFusion Xamarin Components quickly will miss controls when switching to MAUI:

Telerik looks similar...

@ghost ghost locked as resolved and limited conversation to collaborators Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests