Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top