Xamarin iOS 链接器问题 [英] Xamarin iOS Linker Issue

查看:18
本文介绍了Xamarin iOS 链接器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它有一个带有共享代码的 android 和 ios 项目.android 应用程序运行良好,并使用 SDK Only 链接器.我还有一个链接器文件来强制链接器不删除使用的函数 - 这是一个相当大的文件,我也尝试添加一堆保留属性.同样的情况在iOS项目中,但是,做同样的事情是行不通的.它从 EF 中删除了一些东西并抛出这个异常:

I have an application that has an android and ios project with shared code. The android application works perfectly and uses the SDK Only linker. I also have a Linker file to enforce linker not removing used functions - Which is a fairly large file and I've also tried adding a bunch of preserve attributes. The same situation in the iOS project, however, doing the same thing doesn't work. It removes something from EF and throws this exception:

"The type initializer for 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions' threw an exception. ---> System.InvalidOperationException"

整个代码库在没有链接的情况下工作得很好.我添加了一堆 mtouch 参数来尝试跳过它,但这也不起作用.

This whole codebase works perfectly fine without the linking. I've added a bunch of mtouch arguments to try and skip it but that ain't working either.

--linkskip=Microsoft.EntityFrameworkCore 
--linkskip=Microsoft.EntityFrameworkCore.Design 
--linkskip=Microsoft.EntityFrameworkCore.Sqlite 
--linkskip=Microsoft.EntityFrameworkCore.Tools 
--linkskip=Interactive.Async 
--linkskip=Remotion.Linq 
--linkskip=System.Data 
--linkskip=System.Collections.Immutable 
--linkskip=System.Diagnostics.DiagnosticSource 
--linkskip=Microsoft.Extensions.Logging 
--linkskip=System.Interactive.Async 
--linkskip=Microsoft.EntityFrameworkCore.Abstractions 
--linkskip=Microsoft.Extensions.DependencyInjection 
--linkskip=Microsoft.Extensions.Caching.Memory 
--linkskip=System.ComponentModel.Annotations

我将在 NuGet 存储库中添加每个 DLL,这将使链接器无用.这是 iOS 链接器的错误还是我在这里遗漏了什么?我已阅读文档 https://docs.microsoft.com/en-us/xamarin/ios/deploy-test/linker?tabs=windows 并在互联网上到处搜索,但没有任何结果.任何帮助表示赞赏.

I'm about to add every DLL in the NuGet repository which will make the Linker useless. Is this a bug for the iOS Linker or what am I missing here? I've read the documentation https://docs.microsoft.com/en-us/xamarin/ios/deploy-test/linker?tabs=windows and searched everywhere on the internet and nothing comes up. Any help is appreciated.

谢谢,

推荐答案

如果您在 iOS 项目上使用仅链接 SDK 程序集"选项,那么所有这些 --linkskip 参数都不会做任何事情,因为只有 SDK 程序集被链接.因此,EntityFrameworkCore 可能正在使用 Xamarin.iOS SDK 程序集中正在链接的东西.System.Linq 是 SDK 的一部分,并为许多数据库类型添加了扩展方法.

If you are using "Link SDK assemblies only" option on iOS project, then all of those --linkskip arguments won't do anything as only the SDK assemblies are being linked. So the EntityFrameworkCore might be using something that is being linked away that is in the Xamarin.iOS SDK assemblies. System.Linq is part of the SDK and adds extension methods for many database types.

所以我认为您可能遇到了这个问题:https://github.com/xamarin/xamarin-macios/issues/3394

So I think you may be hitting this issue: https://github.com/xamarin/xamarin-macios/issues/3394

如果是这样,请尝试输入:

If so, try putting:

[assembly: Preserve (typeof (System.Linq.Queryable), AllMembers = true)]

在命名空间之外的iOS项目的Main.cs文件中,例如:

in the Main.cs file of the iOS project outside of the namespace, e.g.:

using UIKit;

[assembly: Preserve (typeof (System.Linq.Queryable), AllMembers = true)]
namespace
{
    ...
}

这篇关于Xamarin iOS 链接器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆