【问题标题】:Xamarin.Forms + Xamarin.ios Entityframework Core 2.1.1 build errorXamarin.Forms + Xamarin.ios Entityframework Core 2.1.1 构建错误
【发布时间】:2019-01-15 21:33:46
【问题描述】:

我正在使用 Microsoft.EntityframeworkCore.Sqlite 版本 2.1.1 和 Xamarin.forms .NetStandard 2.0 版本开发 Xamarin.ios 应用程序。我无法在 iPhone 上构建应用程序,出现以下错误:

MTOUCH:错误 MT3001:无法 AOT 程序集“project_name/iOS/obj/iPhone/Debug/device-builds/iphone10.2-11.0.2/mtouch-cache/Build/Microsoft.EntityFrameworkCore.dll”(MT3001 ) (project_name.iOS)

谁能帮我解决这个错误,我尝试将实体框架版本降级到 2.0.0 并将 Microsoft.extension.* 版本降级到 2.0.0。

链接器行为:不链接/仅链接 SDK SDK版本:11.0

【问题讨论】:

    标签: xamarin.forms xamarin.ios .net-standard-2.0 entity-framework-core-2.1 system.memory


    【解决方案1】:

    在我正在处理的项目中实现EntityFrameworkCore 时,我遇到了类似的错误。我的解决方案是在我的 iOS 项目中添加一个文件,并拥有这些内容。另外,我目前正在运行Microsoft.EntityFrameworkCore.Sqlite 2.0.2 版,没有任何问题。

    <?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>
    

    您还需要将该文件 Build Action 设置为 LinkDescription。此外,您不需要将该文件复制到输出目录。它仅在构建期间使用。

    iOS 项目的项目设置中,您需要将--xml=${ProjectDir}/LinkDescription.xml 放入Additional mtouch arguments 部分的iOS Build

    希望这会有所帮助!

    【讨论】:

    • 感谢您的快速回复,我将尝试上述解决方案,但在我的 ios 项目中添加此 xml 文件的位置。另外请不要说我正在为 MVVM 模式使用 Prism.Autofac 框架。它会与棱镜冲突吗?
    • 我已经在我的iOS平台项目中添加了这个文件。我不确定它是否会与 prism 冲突,因为我没有使用过该框架并且不熟悉它。此外,说明在上面的 xml 文件中。当我跟着他们时,一切都很顺利。确保在再次尝试构建之前彻底清洁。
    • 好的,我试试看。
    • 嗨@TaylorD 我尝试了上述解决方案,这次我收到以下错误:{project_path}/iOS/MTOUCH:错误 MT0091:此版本的 Xamarin.iOS 需要 iOS 11.2 SDK(随附Xcode 9.2)。升级 Xcode 以获取所需的头文件或将托管链接器行为设置为仅链接框架 SDK(以尽量避免使用新的 API)。 (MT0091) 我将链接器行为设置为:链接器行为:仅链接 SDK 仅 SDK 版本
    • 如果可以的话,我会更新 Xcode 并尝试一下。我目前正在运行 Xcode 9.4。此外,看起来该错误与EntityFramework 问题无关。我之前遇到过这个问题,更新 Xcode 为我解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 2017-08-21
    • 2018-03-28
    • 2021-10-02
    相关资源
    最近更新 更多