为什么 EFCore 6 不再在 iOS 上运行?

问题描述 投票:0回答:1

我在使用

.net6
构建的 iOS 应用程序上使用 Entity Framework Core 6。它曾经适用于旧版本(EF 和 .net),但现在我收到以下错误:

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.

考虑到用例如此简单,我不确定为什么它会失败。这是表实体:

[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;
    }
}

这是电话:

DbContext db = ...;

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

通过查看调用堆栈和我相当简单的用例,我感觉 EFCore 6 不再在 iOS 上运行。

问题

Entity Framework Core 6 可以在 iOS 上运行吗?如果可以,为什么它现在失败并显示

System.ExecutionEngineException

.net entity-framework-core xamarin.ios .net-6.0 ef-core-6.0
1个回答
0
投票

编辑您的毛伊岛应用程序

.cproj

<!--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> <EnableAssemblyILStripping>false</EnableAssemblyILStripping> </PropertyGroup>
删除

bin

obj
并重建

我看不到性能影响,我们已成功将使用这些设置编译的应用程序发布到 AppStore。

© www.soinside.com 2019 - 2024. All rights reserved.