TinyIoC, Xamarin.iOS, linker settings

时间秒杀一切 提交于 2019-12-07 11:00:58

问题


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".

I'm literally doing something this simple:

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

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();

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>();

Here's the error:

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.

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?

Thank you!


回答1:


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.

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

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.



来源:https://stackoverflow.com/questions/18901310/tinyioc-xamarin-ios-linker-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!