Cross post from Automapper https://github.com/AutoMapper/AutoMapper/issues/2455
When adding AutoMapper >= 6.2.0, the forms iOS project fails to build and outputs a CS1703 error.
The exact error is
Error CS1703
Multiple assemblies with equivalent identity have been imported:
'C:\Users\plebm\.nuget\packages\system.reflection.emit\4.3.0\ref\netstandard1.1\System.Reflection.Emit.dll'
and
'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Reflection.Emit.dll'.
Remove one of the duplicate references.
It seems to be caused by AutoMapper adding an additional dependency of System.Runtime.Serialization.Primitives.4.3.0
in 6.2.0
using VS 15.5.1
Build was successful
Build failed
Seems that automapper is using something that requires Reflection.Emit. That's not going to work in iOS.
@jassmith thanks for the comment. One question though, would Reflection.Emit cause a runtime error or a build error?
AutoMapper uses expression tree compilation, so eventually an Expression.Lambda(...).Compile(). We use Reflection.Emit for a couple of very targeted scenarios.
Basically for us to target iOS we need to make sure we have a target that doesn't use/reference Reflection.Emit at all?
The compile error sounds like the recent problems with 15.5 and binding redirects though.
I had the same problem. My solution was to use a project.json in my ios project like this:
{
"dependencies": {
"System.Reflection.Emit": {
"version": "4.3.0",
"exclude": "all"
}
},
"frameworks": {
"Xamarin.iOS,Version=v1.0": {}
},
"runtimes": {
"win": {}
}
}
@gmwilhelm I didn't know the project.json was still a thing. Today I learn
@jassmith any chance you would review this ticket again? I know you've marked it invalid, but I think this is actually something Xam.Forms should address
I’m trying to reproduce this locally with just a blank NuGet package that
references Reflection.Emit but does not use it. I got the compile error
once but then it mysteriously went away.
On Tue, Jan 2, 2018 at 5:54 PM Wade Baglin notifications@github.com wrote:
@jassmith https://github.com/jassmith any chance you would review this
ticket again? I know you've marked it invalid, but I think this is actually
something Xam.Forms should address—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Xamarin.Forms/issues/1380#issuecomment-354906852,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGYMoqgqceTH4BPe4vqZwLkAoYb1YO0ks5tGsGxgaJpZM4Q-gOM
.
@pleb @jbogard
I am able to reproduce the Multiple Assemblies error in Visual Studio 15.5.5 but not in VSMac. I've created a DevCom item to track this.
FYI: in order to make the workaround above work you might need to restart your VS. That happened for me with VS for Mac.
@SvenEV had the solution in his commit
add this to the csproj file. If you are using PackageReferences
<PackageReference Include="System.Reflection.Emit" Version="4.3.0">
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
I'm writing it here to make it more visible, As far as i have looked the emit Interface is used in Automapper to map for example to interfaces.
Most helpful comment
@SvenEV had the solution in his commit
add this to the csproj file. If you are using PackageReferences
I'm writing it here to make it more visible, As far as i have looked the emit Interface is used in Automapper to map for example to interfaces.