1

I am using Entity Framework Core 6 on an iOS application I built using .net6. It used to work on older versions (both EF & .net) but now I am getting the following error:

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper dynamic-method) AccountTableEntity

object:Thunk1ret_AccountTableEntity_QueryContext_DbDataReader_ResultContext_SingleQueryResultCoordinator (System.Func`2<object[], object>,Microsoft.EntityFrameworkCore.Query.QueryContext,System.Data.Common.DbDataReader,Microsoft.EntityFrameworkCore.Query.Internal.ResultContext,Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryResultCoordinator)' while running in aot-only mode. 

See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information.

I am not sure why it would be failing considering how simple the use case is. Here is the TableEntity:

[Table("Accounts")]
internal sealed class AccountTableEntity
{
    /// <summary>
    /// Gets or sets the data.
    /// </summary>
    [Column("Data")]
    public string Data { get; set; }

    /// <summary>
    /// Gets or sets the ID of the owner of the account.
    /// </summary>
    [Column("UserSid")]
    public string UserSid { get; set; }

    public AccountTableEntity()
    {
        UserSid = string.Empty;
        Data = string.Empty;
    }

    /// <param name="accountTableEntity"></param>
    /// <exception cref="ArgumentNullException">
    /// Thrown if:
    /// - The instance of <see cref="AccountTableEntity" /> is not specified.
    /// </exception>
    public AccountTableEntity(AccountTableEntity accountTableEntity)
    {
        Guard.Argument(accountTableEntity, nameof(accountTableEntity)).NotNull();

        UserSid = accountTableEntity.UserSid;
        Data = accountTableEntity.Data;
    }
}

And here is the call :

DbContext db = ...;

foreach (AccountTableEntity account in db.Accounts.ToList())
{
   //
}
     

By looking at the callstack and my pretty straightforward use case, I am getting the feeling that EFCore 6 does not work on iOS anymore.

Question

Can Entity Framework Core 6 work on iOS and if yes, why is it failing now with an System.ExecutionEngineException?

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
Kzryzstof
  • 7,688
  • 10
  • 61
  • 108
  • 1
    Actually I'm impressed that this was worked before. EF Core uses `LambdaExpression.Compile` everywhere, but iOS has limitation that generated code cannot be executed. Probably better to create issue in EF Core`s GitHub repository. – Svyatoslav Danyliv Jan 02 '22 at 15:20
  • @SvyatoslavDanyliv Yes, I agree, especially after seeing the callback. I was using Microsoft.EntityFrameworkCore 3.1.4 and Xamarin.iOS and it did work (after adding --linkskip mtouch options). – Kzryzstof Jan 02 '22 at 19:23
  • 1
    iOS don't allow JIT mode , try to raise the issue on github for better support : https://github.com/dotnet/EntityFramework.Docs/issues?q=is%3Aopen+is%3Aissue. – ColeX Jan 03 '22 at 08:30
  • @ColeX-MSFT Thanks! I am switching to SQLite instead; it seems more appropriate to such environment. – Kzryzstof Jan 03 '22 at 14:00
  • Correct, SQLite is more suitable for mobile app . – ColeX Jan 04 '22 at 01:38

1 Answers1

0

Edit .cproj of your maui app

    <!--IOS RELEASE-->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
        <!--to be able to use EF core dynamic stuff-->
        <MtouchExtraArgs>--interpreter</MtouchExtraArgs>
        <UseInterpreter>True</UseInterpreter>
    </PropertyGroup>

Delete bin obj and rebuild

I can see no performance impact and we have successfully published our app compiled with theses settings to AppStore.

Nick Kovalsky
  • 5,378
  • 2
  • 23
  • 50