Xamarin.iOS project: CS1703: Multiple assemblies with equivalent identity have been imported

ossentooossentoo GBMember ✭✭

I've got a cross platform (iOS and Android) Xamarin solution using .NET Standard 2.0. The solution is being built by Visual Studio 2017 (I've tried both the current and preview versions). The Forms and Android projects build fine. However, the iOS fails to build, with the following error:

1>CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'C:\Users\newuser.nuget\packages\system.reflection.emit\4.3.0\ref\netstandard1.1\System.Reflection.Emit.dll' and 'C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Reflection.Emit.dll'. Remove one of the duplicate references.

I've tried many work arounds as described here:

oren.codes

www.hanselman.com

github.com/NuGet

Unfortunately none of these suggestions work. I have also tried to add the System.Reflection.Emit nuget package directly to the Forms and/or to the iOS projects directly. This doesn't work either. Note that originally, the The System.Reflection.Emit package wasn't referenced directly by anything in the solution. It is being pulled in by the following nuget packages which are being explicitly referenced:

  • Acr.DeviceInfo (5.0.5)
  • akavache (6.0.0-alpha0038)
  • AutoMapper (6.2.2)
  • Microsoft.Identity.Client (1.1.1-preview0040)
  • Newtonsoft.Json (10.0.3)

Finally, I have tried the update-package -reinstall command in the package console to reinstall all packages for the iOS project. This doesn't work either.

-- update

Just to make this clear, neither the Xamarin Forms or the Xamarin iOS project directly reference System.Reflection.Emit. That package is being pulled in as a dependency of other nuget packages, just from packages that are installed into the Xamarin Forms project. I have confirmed all of the dependencies that are referenced by Nuget, are using the same version. See these screenshots:

Referenced Emit dependencies from Visual Studio
Expanded referenced Emit dependencies

It seems to me that the problem (as the error says) is that there is an old version of System.Reflection.Emit that was installed by Visual Studio. However, I can't find a way of ignoring it and using the version of System.Reflection.Emit instead. As I've said above, I have tried to use a project.json file in the Xamarin.iOS project, and manually ignoring, but this doesn't work.

Does anyone else have any ideas?

As an aside, I notice that this bug is still open for Xamarin.

Xamarin Bugs

FYI: I have added this question to Stackoverflow as well.

Answers

  • MattCrombieMattCrombie AUUniversity ✭✭

    Hi @ossentoo , did you manage to solve this issue? I'm having the exact same problem with the same packages and have tried everything you have as well but with no luck.

  • ossentooossentoo GBMember ✭✭
    edited February 2018

    Unfortunately not - no @MattCrombie. I'm beginning to suspect it is a problem with one of the Xamarin packages (potentially Xamarin.iOS). I've give it a few more days to see if there's any response then perhaps raise a bug.

    I've added a comment to this bug in Xamarin Bugzilla.

    https://bugzilla.xamarin.com/show_bug.cgi?id=57849

  • MattCrombieMattCrombie AUUniversity ✭✭

    After spending hours trying to resolve this myself I may have found a solution. Although it does feel wrong, it has got me past the issue.

    Moving/Deleting the Xamarin.iOS version of System.Reflection.Emit.dll has solved the build problem for me and enabled me to deploy and run my app on a device. I don’t know what side effects it might have so will need more testing but I thought I’d share what’s worked for me so you can test it as well.

    I was running on macOS Visual Studio 2017 but switched over to Windows to try and fix and first fixed on there then tried same approach on macOS and it worked as well.

    On windows, go into the following directory and move the System.Reflection.Emit.dll somewhere else (you could delete but I wanted to keep a copy I case this has some undesired effects down the track):

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades

    On mac the following directory has it:

    /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades

    Like I say, it feels wrong but for now it’s got me past an issue that’s had me blocked for a couple of days so willing to just move on and hope there’s no side effects. I’d be interested to know your experience with it and if you come across anything else for the future too.

  • ossentooossentoo GBMember ✭✭

    Understood. Yes, that works locally. thanks for the approach Matt.

    The issue is that I also use appcenter to build and distribute my app. The app there is built using the build machines as created by Microsoft (with standard build tools I imagine).

    Those machines will still have that library, so unfortunately this solution only works locally.

    I hope the Xamarin guys can find a permanent solution.

  • MattCrombieMattCrombie AUUniversity ✭✭

    I've hit similar issue but I'm using VSTS with a local Mac build host that I can apply the same fix to that machine as well. It's frustrating though and I hope Xamarin can provide some sort of solution here.

  • ossentooossentoo GBMember ✭✭
    edited February 2018

    Thanks a lot @DirkWilhelm.

    The way to resolve the issue is to add this to the iOS project file.

    <PackageReference Include="System.Reflection.Emit">
      <Version>4.3.0</Version>
      <ExcludeAssets>all</ExcludeAssets>
    </PackageReference>
    

    Of course you need to make sure the nuget package has been added to the iOS package first.

  • Gmoney494Gmoney494 USMember ✭✭

    Hey guys, I had this same issue but around a custom nuget package I had created. After speaking to a team member, he suggested removing the nuget package for automatic nuget packaging. So this adds an extra step when you wish to create the actual .nupkg, however it removed the error and builds no problem.

    Hope this helps someone.

  • MattKochMattKoch USMember ✭✭

    @Gmoney494 said:
    Hey guys, I had this same issue but around a custom nuget package I had created. After speaking to a team member, he suggested removing the nuget package for automatic nuget packaging. So this adds an extra step when you wish to create the actual .nupkg, however it removed the error and builds no problem.

    Hope this helps someone.

    Can you elaborate? What do you mean by "removing the nuget package for automatic nuget packaging?"

  • Gmoney494Gmoney494 USMember ✭✭

    @MattKoch in the properties for a project under "Nuget Package", there is a checkbox for the "Build" tab. Selecting that would sometimes add a Nuget package to help with automatic packaging, called "nuget.packaging" or something of the sorts. This for some reason would cause the error, a bug of sorts im assuming.

  • MattKochMattKoch USMember ✭✭

    @Gmoney494 said:
    @MattKoch in the properties for a project under "Nuget Package", there is a checkbox for the "Build" tab. Selecting that would sometimes add a Nuget package to help with automatic packaging, called "nuget.packaging" or something of the sorts. This for some reason would cause the error, a bug of sorts im assuming.

    This was the issue! Thank you for responding!

    Just to add some clarity, I had to remove the NuGet.Build.Packaging dependency from my .NET Standard 2.0 library. After doing that, re-packaging the *.nupkg, and re-adding the package to my Xamarin.iOS project, builds succeeded.

  • Gmoney494Gmoney494 USMember ✭✭
    edited July 2018

    @MattKoch said:

    @Gmoney494 said:
    @MattKoch in the properties for a project under "Nuget Package", there is a checkbox for the "Build" tab. Selecting that would sometimes add a Nuget package to help with automatic packaging, called "nuget.packaging" or something of the sorts. This for some reason would cause the error, a bug of sorts im assuming.

    This was the issue! Thank you for responding!

    Just to add some clarity, I had to remove the NuGet.Build.Packaging dependency from my .NET Standard 2.0 library. After doing that, re-packaging the *.nupkg, and re-adding the package to my Xamarin.iOS project, builds succeeded.

    No problem! I couldnt find any documentation or post about it onlinen (if it werent for my team member telling me) so i wanted to leave it here in case anyone else had the same problem. Glad i could help!

  • BaluBalu Member

    I got exact same error after upgrading Unity from version 5.8.6 to 5.8.11.

  • miguelitoBarreramiguelitoBarrera ESMember ✭✭

    Oh my GOD! Thanks @Balu . I downgrade to 5.8.6 and all work fine!

  • MaxenceMaxMaxenceMax Member ✭✭

    @MattKoch Thanks a lot .... I was so sad before your post !

Sign In or Register to comment.