Xamarin.iOS 链接器和反射问题 [英] Xamarin.iOS linker and reflection issue

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

问题描述

在我的 Xamarin.iOS 项目中,我需要减小程序集大小(Apple 对 AppStore 应用程序的要求),并且我需要打开链接器,将链接器行为设置为仅链接框架 SDK";或链接所有".

In my Xamarin.iOS project I need to reduce the assembly size (Apple's requirement for AppStore applications), and I need to turn on linker, setting the linker behavior either to "Link Framework SDKs only" or "Link All".

当我选择了仅链接框架 SDK"时;在链接器行为中,我在构建项目时收到编译错误:

When I've selected "Link Framework SDKs only" in Linker behavior I get the compilation error upon building the project:

无法解析引用System.Void System.Data.SqlClient.SqlCommandBuilder::DeriveParameters(System.Data.SqlClient.SqlCommand)",从方法'System.Void DevExpress.Xpo.DB.MSSqlConnectionProvider::CommandBuilderDeriveParameters(System.Data.IDbCommand)'引用在System.Data.SqlClient,版本=4.4.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a"中.

Can't resolve the reference 'System.Void System.Data.SqlClient.SqlCommandBuilder::DeriveParameters(System.Data.SqlClient.SqlCommand)', referenced from the method 'System.Void DevExpress.Xpo.DB.MSSqlConnectionProvider::CommandBuilderDeriveParameters(System.Data.IDbCommand)' in 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

为了解决这个问题,我找到了所有答案,建议将全部链接"转为链接".链接器行为选项中的选项.

To fix this issue all answers I have found recommendation to turn "Link All" option in the Linker behavior option.

当我选择链接全部"时,项目编译正常,但在运行时我在 IoC 容器代码上遇到系统异常(类型 AAA 没有实现接口 BBB),因为我使用反射,并且链接器带有Link All"选项通过反射影响代码.据我所知,对于使用反射的项目,不建议使用此链接器选项 (Link All).

When I've selected "Link All", the project compiles okay, but at the runtime I get system exception on the IoC Container code (type AAA does not implement the interface BBB), because I use reflection, and linker with "Link All" options affects the code with the reflection. And as far as I know this linker option (Link All) is not recommended for the projects where reflection is being used.

此时我有哪些选择?

推荐答案

链接器配置

我怀疑您最好的选择是查看定义一个配置文件来告诉链接器必须保留什么.微软文档站点.

还有一些其他选项,但在这种情况下可能并不严格适用,或者您可能希望使用组合.

There are some other options but may not strictly apply in this case or you may wish to use a combination.

您可以为链接器提供额外的定义,以确保类型、方法和/或字段不会从您的应用程序中删除.在您自己的代码中,首选方法是使用 [Preserve] 自定义属性,如 在 iOS 上链接在 Android 上链接 指南.

You can provide extra definitions to the linker to ensure the type, methods and/or fields are not eliminated from your application. In your own code the preferred way is to use the [Preserve] custom attribute, as discussed in the Linking on iOS and Linking on Android guides.

链接每个平台当然是可能的,但是我怀疑您想保留共享项目中的内容,这就是为什么我认为配置文件适合您.

Linking for each platform is certainly a possibility however I suspect that you want to preserve things in your shared project which is why I think the config file will be right for you.

这种方法使您能够在不同级别(例如,程序集或类级别以保留所有内容或定义为单个属性/方法等).

This approach gives you the ability to define at varying levels (e.g. assembly or class level to keep everything or down to individual properties/methods, etc.).

我非常不喜欢这个选项,但有些人发现证明您可以保留部分代码或只是接受它是一种解决方案既快捷又容易.

I dislike this option very much but some people find it quick and easy to either prove you can keep parts of the code or just accept it is a solution.

您本质上创建了一个对要保留的方法/属性的实际引用的类.

You essentially create a class of actual references to the methods/properties that you want to be kept.

public class LinkerPleaseInclude
{
    public void Include(MyType arg)
    {
        arg.MethodIDontWantRemoved();
    }
}

请注意,我从 本网站

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

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