TinyIoC,Xamarin.iOS,链接器设置 [英] TinyIoC, Xamarin.iOS, linker settings

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

问题描述

我正在努力让TinyIoC在Xamarin.iOS上工作,但我没有太多运气。我的项目链接器设置被设置为仅限链接SDK程序集。

I'm trying to get TinyIoC working on Xamarin.iOS, but I'm not having a lot of luck. My project linker settings are set to "Link SDK assemblies only".

我实际上做的很简单:

public interface IPerson { int age { get; } }
public class Person : IPerson { public int age { get { return 99; } } }

然后我的注册码看起来像这样(我刚把它放在我的AppDelegate中)玩具应用程序):

Then my registration code looks like this (I've just placed it in my AppDelegate in a toy app):

TinyIoCContainer.Current.Register<IPerson,Person>.AsMultiInstance();

当我尝试抓取一个IPerson时,我得到一个运行时异常,说IPerson无法解析(这个代码在玩具应用程序的AppDelegate中的注册代码之后立即找到):

When I attempt to grab an IPerson, I get a runtime exception saying that IPerson cannot be resolved (this code is found immediately after the registration code in the AppDelegate of the toy app):

IPerson person = TinyIoCContainer.Current.Resolve<IPerson>();

这是错误:

Unable to resolve type: TinyTest.IPerson

但是,如果我改变了链接器设置为不要链接,一切正常。但这显然是站不住脚的,因为二进制文件变得非常庞大。

If, however, I change the linker settings to "Don't link", everything works fine. This is obviously untenable, though, because the binary becomes enormous.

我尝试在IPerson接口和Person类上放置[Preserve]属性,但没有骰子。我也试过手动声明一个IPerson类型的变量并用一个新的Person()实例化它然后抓住age属性,只是为了确保该类型包含在构建中,但也没有运气。

I've tried placing [Preserve] attributes on the IPerson interface and the Person class, but no dice. I also tried just manually declaring a variable of type IPerson and instantiating it with a new Person() and then grabbing the age property, just to make sure the type was included in the build, but no luck there either.

感觉我在这里错过了什么 - 有人能指出我正确的方向吗?

Feel like I'm missing something here - can someone point me in the right direction?

谢谢!

推荐答案

这是 bug 因为反射用于调用内部表达式< TDelegate> 构造函数。

This is a bug because reflection is used to call an internal Expression<TDelegate> constructor.

链接器无法分析反射使用情况(超出静态分析),因此必须了解那些特殊情况。

The linker cannot analyze reflection usage (it's beyond static analysis) so it must be aware of those special cases.


这显然是站不住脚的,因为二进制文件变得非常庞大。

This is obviously untenable, though, because the binary becomes enormous.

继续使用默认的链接SDK 选项,但将 - linkskip = System.Core 添加到其他mtouch参数,在项目选项 iOS Build 中。

Keep using the default Link SDK option but add the --linkskip=System.Core to your Additional mtouch arguments, inside your Project Options, iOS Build.

这样只有System.Core(来自SDK)不会挂钩,尺寸的增加会小得多。当然,这只是一个解决方法,直到新版本正确解决问题。

That way only System.Core (from the SDK) will not be linked and the increase in size will be much smaller. Of course this is only a workaround until a new version fix the issue properly.

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

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