3

I spent 2 days googling, trying to resolve conflict situation with dll versioning in Xamarin. I saw a lot of posts with identical issues (just different NuGet packages) but as I saw, no concrete solution anywhere. I will try to summarize briefly here.

I am using Xamarin for Android (Not Xamarin Forms). This project references my .NET standard 2.0 (.NET Core) project that contains all core logic. I Installed Automapper via NuGet in my core project and suddenly I have build warning that describes the conflict. Conflict is that Xamarin for Android (Mono) uses Microsoft.Csharp.dll version 2.0.5.0 and Auto mapper which is in referenced Core project uses Microsoft.Csharp.dll 4.0.0.0

Here is the output from build process related to mentioned:

    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". (TaskId:131)
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. (TaskId:131)
2>      References which depend on "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll]. (TaskId:131)
2>          C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll (TaskId:131)
2>            Project file item includes which caused reference "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll". (TaskId:131)
2>              Microsoft.CSharp (TaskId:131)
2>      References which depend on "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" []. (TaskId:131)
2>          C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll (TaskId:131)
2>            Project file item includes which caused reference "C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll". (TaskId:131)         C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll (TaskId:131)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,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.

So, build process has chosen an older version from Xamarin (this is confirmed because I extracted APK to see which dll is physically inside and found 2.0.5.0)

Now, the summary of the questions is:

  1. If I leave the warning and accept current situation, I will have Microsoft.Csharp.dll 2.0.5.0 I suppose Android project is OK with this since it originally references this version, but how will AutoMapper behave since it is built with 4.0.0.0 reference? If it uses some new features, and the old version doesn't have them, it is not good.
  2. Can I somehow force Xamarin to use Microsoft.Csharp.dll 4.0.0.0 since I don't see this reference directly (Mono reference is using it)? I can't use the binding redirect from app.config since Xamarin for Android doesn't support app.config. Even if there is a way somehow, is it smart solution since maybe Microsoft.Csharp 4.0.0.0 is not backward compatible with 2.0.5.0
  3. If 1 or 2 are not good solutions, is it possible somehow (codebase path or something else) to make the situation to have both versions and that every component references its original?

This issue with AutoMapper is just an example, but basically, this case can happen with any other package. I saw that it was actually with NewtonJson and is solved in the new version of NewtonJson package where reference to Miscrosoft.Cshap.dll is removed.

Miloš
  • 149
  • 1
  • 12
  • 1
    I have not yet seen an issue with #1. I believe ignoring it is the right way to go until https://github.com/Microsoft/msbuild/issues/1712 and https://github.com/Microsoft/msbuild/issues/608 are fixed. – Jon Douglas Nov 03 '18 at 17:58
  • @JonDouglas Thanks for the answer. Can you please provide an explanation so I can understand what is actually happening here under the hood. As I understand, only valid fix for this is update of Xamarin to use newer version of Microsoft.Csharp library, since if it is using the old one and build mechanism chooses it to be in the package, then all other components that reference newer version of this library (like AutoMapper for example) will use this old one instead, with lack of features that were introduced after (major version is changed from 2 to 4). Correct me if I am wrong, please. – Miloš Nov 03 '18 at 18:36
  • 1
    "2.0.5.0" means the assembly is just a referenced assembly for Portable Class Library, https://blog.lextudio.com/the-rough-history-of-referenced-assemblies-7d752d92c18c You can safely ignore such warnings. It is too long a story to tell. – Lex Li Nov 03 '18 at 23:06
  • @LexLi Thanks for explanation and link. I will add one more reference that can be very useful to all interested in this subject. https://github.com/dotnet/standard/blob/master/docs/history/evolution-of-design-time-assemblies.md – Miloš Nov 04 '18 at 20:12
  • @Miloš So, have you got rid of the warning? I have the same condition like you (with AutoMapper as well). If so, could you provide it as an answer? – Adam Nov 26 '18 at 22:54
  • 1
    @Adam Warning is still there, I just ignored it like suggested. – Miloš Nov 28 '18 at 11:07

0 Answers0