0

I'm working on Xamarin.ios application with Microsoft.EntityframeworkCore.Sqlite version 2.1.1 with Xamarin.forms .NetStandard 2.0 version. I'm unable to build the application on iPhone, getting the below error:

MTOUCH: Error MT3001: Could not AOT the assembly 'project_name/iOS/obj/iPhone/Debug/device-builds/iphone10.2-11.0.2/mtouch-cache/Build/Microsoft.EntityFrameworkCore.dll' (MT3001) (project_name.iOS)

Could any one please help me to get through the error, I tried to downgrade the entityframework version to 2.0.0 and also downgrade the Microsoft.extension.* version to 2.0.0.

Linker behavior : Don't Link/ Link SDK only SDK Version: 11.0

1 Answers1

1

I had a similar error when implementing EntityFrameworkCore in the project I am working on. The solution for me was to add a file to my iOS project, and have these contents. Also, I am running Microsoft.EntityFrameworkCore.Sqlite version 2.0.2 currently with no problems.

<?xml version="1.0" encoding="utf-8" ?>
<linker>
    <!-- LinkDescription.xml. File added to iOS project by @cwrea for adaptation to EF Core.

    Prevents runtime errors when reflection is used for certain types that are not otherwise referenced
    directly in the project, and that would be removed by the Xamarin linker.

    These kinds of runtime errors do occur in particular when using Entity Framework Core on iOS. EF Core's
    query parser does reference certain .NET methods _only_ via reflection, and it is those reflection-only
    instances that we need to guard against by ensuring the linker includes them. For the curious, search
    for mentions of "GetRuntimeMethod" at https://github.com/aspnet/EntityFramework. Use of EF Core more
    advanced than this sample may require additional types/methods added to those below.

    Include the following in the project build settings under "Additional mtouch arguments":
      [hyphen][hyphen]xml=${ProjectDir}/LinkDescription.xml

    There is supposed to be a "LinkDescription" build action for this linker config file so the step above
    shouldn't be necessary, but at time of writing Visual Studio 2017 for PC doesn't show that build action
    in iOS projects, even though it is an option within iOS projects on Visual Studio 2017 for Mac.
    -->
    <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>

You will also need to set that files Build Action to LinkDescription. Also, you don't need to copy that file to the output directory. It is only used during the build.

In your project settings for the iOS project, you will need to put --xml=${ProjectDir}/LinkDescription.xml in the Additional mtouch arguments section in iOS Build.

Hope this helps!

TaylorD
  • 687
  • 3
  • 7
  • thanks for the quick reply, I'll try the above solution but where to add this xml file in my ios project. Also please not that I'm usimg Prism.Autofac framework for MVVM pattern..will it conflict with the prism ? – Mayank Shrivastava Aug 09 '18 at 05:03
  • I have added this file in my `iOS` platform project. I'm not sure if it will conflict with prism as I haven't used that framework and am not familiar with it. Also, the instructions are in the **xml** file above. When I followed them, it went smoothly. Make sure you clean fully before trying to build once again. – TaylorD Aug 09 '18 at 13:06
  • Sure, I'll give a try. – Mayank Shrivastava Aug 09 '18 at 13:28
  • Hi @TaylorD I tries the above solution and this time I got the below error: {project_path}/iOS/MTOUCH: Error MT0091: This version of Xamarin.iOS requires the iOS 11.2 SDK (shipped with Xcode 9.2). Either upgrade Xcode to get the required header files or set the managed linker behaviour to Link Framework SDKs Only (to try to avoid the new APIs). (MT0091) I set linker behavior to: Linker behavior :Link SDK only SDK Version Only – Mayank Shrivastava Aug 10 '18 at 06:26
  • If you can, I would update Xcode and try it then. I am currently running Xcode 9.4. Also, looks like that error isn't associated with the `EntityFramework` issue. I have gotten that issue before and updating Xcode fixed it for me. – TaylorD Aug 10 '18 at 13:07