Skip to end of metadata
Go to start of metadata

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:

Android

  1. 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.

    System.Core.xml

    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.

    System.Core.xml
  2. Change the Build Action of the .xml files into LinkDescription as shown in the following screenshots:

    Visual StudioXamarin
  3. Afterwards, you can build your APK as usual and it will work as expected.

iOS

  1. Right click your .iOS project and choose the Options 
  2. 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



  3. 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:
    --linkskip=System.Core --linkskip=mscorlib 

Customizing Your Own Linker

In case you want to create your own linker you can read this article by Xamarin: 

https://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/