How can I use AutoMapper with my Xamarin.iOS project?

automapper, xamarin.ios

Solution

This issue is temporarily resolved - I had to hack out the offending symbols in AutoMapper and recompile it. Please see automapper issue #429 for more information on what symbols I removed. Until AutoMapper is updated to fix this problem, that's how you have to solve it for now.

The reason for this is explained concisely in another StackOverflow question - basically there are subtle differences between the .NET and Mono frameworks that in this case are incompatible with AutoMapper.

This answer previously stated that you should turn off linking to work with AutoMapper. While you can do this for development, it's not suitable for production use as it will yield a massive binary and you will not be able to submit your app to the app store.

Problem

It seems that when I reference AutoMapper v3.1.0 in my Xamarin.iOS project, the build fails with this error message: ``` Error MT2002: Failed to resolve "System.Linq.Expressions.Expression System.Linq.Expressions.ExpressionVisitor::Visit(System.Linq.Expressions.Expression)" reference from "System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" (MT2002) ``` When I roll back to the revision before I added this, it all works fine. Unfortunately, I've already done quite a bit of work with AutoMapper in my unit tests and it would be problematic to remove it now. I guess that's a lesson to learn: just because it works in a test doesn't mean it works in Xamarin.iOS. I would be very grateful if anyone has any ideas. Edit: I have now discovered a MonoTouch directory in the AutoMapper package, but referencing the `AutoMapper.dll` and `AutoMapper.iOS.dll`s found within does not solve the problem. Edit #2: This issue only occurs when building for the device - I guess the MSIL to native converter doesn't like AutoMapper for some reason. I'm trying to find a way to "hint" to this compiler that we need these symbols, which is what I think the purpose of the `LinkerPleaseInclude.cs` file is.

Original source

Related problems