Xamarin Android Entity Framework Core linker issue

396 Views Asked by At

I used Entity Framework Core in one of my Xamarin Android apps. When I use SDK only as of the linker option then the app works properly.

However, when I use SDK and user assemblies add linker option, the app crashes as several Entity Framework Core related required classes are removed by the linker.

Let me know if there is anything I could do to preserve the classes.

Note: I already tried referencing the Entity Framework Core classes in a dummy class.

2

There are 2 best solutions below

0
GiampaoloGabba On

You have to configure the linker.

  • Create a new xml in your Android project, call it linker.xml
  • Set the build action to LinkDescription
  • Paste this code:
    <?xml version="1.0" encoding="utf-8" ?>
    <linker>
      <assembly fullname="mscorlib">
        <type fullname="System.String">
          <method name="Compare"></method>
          <method name="CompareTo"></method>
          <method name="ToUpper"></method>
          <method name="ToLower"></method>
        </type>
      </assembly>
      <assembly fullname="System.Core">
        <type fullname="System.Linq.Expressions.Expression`1"></type>
        <type fullname="System.Linq.Queryable"></type>
      </assembly>
    </linker>

More complex usage of EF Core is likely to require a few more types and methods added.

0
Alex On

Apparently my case is much more complex. I changes the file to

  <linker>
     <assembly fullname="mscorlib">
        <type fullname="System.String" />
     </assembly>
     <assembly fullname="System.Core">
        <type fullname="System.Linq.Expressions*" />
        <type fullname="System.Linq.Queryable*" />
     </assembly>
     <assembly fullname="System.Collections">
        <type fullname="System.Collections.Generic*" />
     </assembly>
  </linker>

but it still didn't fix the issue. Did anybody figure out the complete exclusion list for the entity framework core to work?