Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

    Code Block
    titleSystem.Core.xml
    languagexml
    <?xml version="1.0" encoding="utf-8" ?>
    <linker>
      <assembly fullname="System.Core">
        <type fullname="System.Linq.Expressions.Expression`1"></type>
        <type fullname="System.Linq.Queryable"></type>
      </assembly>
    </linker>

    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.

    Code Block
    titleSystem.Core.xml
    languagexml
    <?xml version="1.0" encoding="utf-8" ?>
    <linker>
      <assembly fullname="System.Core">
        <type fullname="System.Linq.Expressions.Expression`1"></type>
        <type fullname="System.Linq.Queryable"></type>
      </assembly>
      <assembly fullname="mscorlib" />
    </linker>
  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.

    Modern note

    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/


Related Topics

Content by Label
spaces@self
reversetrue
showLabelsfalse
max5
sortmodified
labelskb-how-to-article -enable-linq-expressions-in-production-ready-application-release-build
showSpacefalse
typepage