Linking a Xamarin iOS lib with indirect code references


I'm developing a Xamarin library that contains Core (.NET Standard 2.0), Android and iOS libraries to display a custom page.
So there is a CustomPage class in the core and a page renderer on each mobile OS for this page. So far no problems.

Now I wanted to use this libraries in a Xamarin Forms application. I'm referencing the library projects in the Xam Forms solution and add a reference on each platform to the target library.

While I tested this on Android everything worked fine. On iOS there is a linker problem which strips my library out as part of the iOS linker optimization. (There is no direct reference to any code in the iOS library. Only the page renderer is used with an indirect access over the "Assembly: ExportRenderer(..)" attribute).

Only when I access any direct code from the iOS library then the iOS library is linked too.

I've tried to add the "[Assembly: Preserve]" to the AssemblyInfo.cs in the iOS library but this does not help.

Any solution here that doesn't need direct code references?

Best Answer


  • LandLuLandLu Member, Xamarin Team Xamurai

    Did you try to use linker behavior on iOS? When you set it to [Link All](It will modify user code "Link All"), it will modify user code. I recommend you to use the default mode: Don't Link for simulator and Link Frameworks only for real device.

  • SonnenspeerSonnenspeer Member ✭✭
    edited August 2018

    Hi. Thanks for your reply.

    I'm testing this on an iPhone (real device) and the linker is set by default to "Link Framework SDKs Only" using VS 2017.

    The library is not included without any direct reference.

  • SonnenspeerSonnenspeer Member ✭✭
    Yes. This is what I am doing as a workaround. Would be of course better if it could stay preserved without any dummy.
Sign In or Register to comment.