How to force assembly link

LaurentColtatLaurentColtat FRMember

Hi guys,

First I would like to apologize for my english : I'm french ;)

I'm sure my question is a little bit trivial but as I am a xamarin newbie, I need some help :)

Here my problem : I'm currently working on a plugin injection system, which allows to dynamically load a plugin at runtime according to an XML configuration file which defines the plugin implementation class to be loaded.

My plugin interface is an assembly named IPluginLib, while each plugin implementation reside into its own assembly named PluginXXXLib.

My application refers the plugin interface assembly as well each plugin implementation assemblies.

But as I do not have explicit references to implementation plugin classes (my code using only the plugin interface type), the plugin implementation assemblies are not linked because of static analysis preformed to select which assemblies to be linked.

So I would like to know if there is a trick to force my plugin implementation assemblies to be linked with my application ?

10x in advance for your advices.

Answers

  • DavidPuplavaDavidPuplava USMember ✭✭

    Hi Microscotch -

    I am experiencing this very same issue. I don't have an answer yet but I'll write back as soon as I find out how to fix this.

    David

  • LaurentColtatLaurentColtat FRMember
    edited September 2013

    I found a workaround thanks to this post

    It consists to introduce a class where its static constructor performs calls to an empty static generic parameterized method, with the class references to be included into the build app.

    Here a sample assuming you got 2 plugins implementations into 2 dedicated library projects (Plugin1 and Plugin2) you want to be included into your final app

    using System;
    
    namespace Plugins
    {
      // This class is a workaround for iOS in order to force assembly plugin to be 
      // include into target app
      // See http://stackoverflow.com/a/12401947 for details.
      public class Registry
      {
         // Trick source: 
         // http://forums.xamarin.com/discussion/comment/7870/#Comment_7870
         static PluginRegistry() {
           // Add a call to registerPlugin<device.class.full.namespace>() 
           // and a reference to its project in order to force inclusion of 
           // its related assembly
           RegisterPlugin<Plugins.Impl.Plugin1> ();
           RegisterPlugin<Plugins.Impl.Plugin2> ();
         }
    
         private static void RegisterPlugin<T>() where T:Plugins.IPlugin {} 
       }
    }
    

    Laurent.

Sign In or Register to comment.