When building production in both iOS and Android, Xamarin method of deployment for iOS and Android to reduce size of the apps is the recommended way to optimized your application. However, when the linker is enabled, it may cause unexpected errors when the app tries methods which may not be directly referenced by the application, such as LINQ expressions.
If the LINQ is ignored, usually user will encounter this error: Unable to perform data operation due to an error: Sequence contains no matching element.
In order to use fully functional LINQ expressions, you will have to "tell" the Android/iOS linker to include the System.Xml.Linq assembly (do not exclude that assembly).
Here's how to enable the LINQ expressions in your production build:
Download this file: System.Core.xml and put it directly in the root of your Android project so your project becomes:
Here's the content of System.Core.xml file.
In fact, you can name the .xml file as anything you want, for example: Assemblies.xml. Also, for Release build, you might need to include linkskip mscorlib as well.
Change the Build Action of the .xml files into LinkDescription as shown in the following screenshots:
Visual Studio Xamarin
Afterwards, you can build your APK as usual and it will work as expected.
- Right click your .iOS project and choose the Options
- Navigate to the iOS Build Tab, change the linker behaviour to "Link Framework SDKs Only" incase you do not yet. Then type this inside the Additional mtouch arguments: --linkskip=System.Core
Afterwards, you can build your application as usual and it will work as expected.If you wish you perform linkskip on multiple assemblies, use this:
Customizing Your Own Linker
In case you want to create your own linker you can read this article by Xamarin: