none
Load XAP from Other Non-MEF Solution

    Question

  • Hi, Let's say that people build a XAP and then give it to me, and I want to load that XAP in my Silverlight Business Application on the HomePage. (maybe inside an itemscontrol) Is this possible? I have read various resources about Dynamic Loading , but all of the examples assume that the plugin has the export attribute (i.e. have to implement MEF). If that plugin doesn't use MEF, can I still load it? Thanks, crsnt
    Friday, June 25, 2010 1:13 AM

All replies

  • Well, DeploymentCatalog will cause all assemblies in a XAP to load regardless of whether it contains MEF parts or not. That means you "could" use it to just load up some assemblies and then use reflection to get to them.

    You can also use property exports to make non-MEF things appear to MEF. That would allow customers to add an adapter part to their XAPs which containers property exports that make their non-MEF things appear to MEF. This would require them to add an assembly to the XAP which contains that adapter part though. You can read more on property exports in this post here:

    Regards

    Glenn

     

    Friday, June 25, 2010 3:36 AM
  • Well, DeploymentCatalog will cause all assemblies in a XAP to load regardless of whether it contains MEF parts or not. That means you "could" use it to just load up some assemblies and then use reflection to get to them.

     

    And it would still resolve assembly dependencies ?

    (If the main application has already loaded the Silverlight toolkit, then the assembly I am loading does not have to include it in it's .xap file (set CopyLocal= false)) (Glenn I know you know this I am including the explanation for others :))

    If so Hmmm.... :)

    Monday, June 28, 2010 9:11 AM
  • Michael:

    Yes as long as those dependencies were either previously loaded or within the XAP itself.

    Wednesday, June 30, 2010 2:48 AM
  • How would you use reflection to get the loaded assemblies from MEF? I need AsseblyInfo from the loaded xap.
    Thursday, July 08, 2010 3:01 AM
  • Take a look at this post where I roll my own MEF importer by parsing the actual XAP stream, source included:

    http://csharperimage.jeremylikness.com/2010/05/silverlight-out-of-browser-dynamic.html

    What you would need to do is take the AssemblyParts and/or Assembly and then call the GetType method with the type you are targeting to instantiate it (or use the Activator, once you've parsed the assembly) 

    Monday, July 12, 2010 5:18 PM
  • Hi,

    I'm facing a problem with MEF... that might be related.

    I have these requirements:

    1) I have different modules. Each module has a menu –user control- that is being drawn on the main app menu. So in the view that is responsible for drawing the main menu, I have a collection of IMenu –what is being exposed on every module menu- that MEF injects for me by loading the modules xaps using a variant of the DeploymentCatalogService in your blog.

    2) I also wanted to implement a custom NavigationContentLoader so a user can type something like /<Module>/<View>/ and I can put the corresponding view in the ContentFrame.

    I was able to fulfill requirement 1) but when it comes to requirement 2) I’m not being able to get to the type of the view I need to instantiate by using reflection.

    So when doing:

    Type t = Type.GetType(“Modules.Module1.View1”, false, true);
    object instance = Activator.CreateInstance(t);



    t is always null.

    Does it mean I’m not able to access the assemblies in Module1 even when its xap was previously downloaded when this menu was drawn?

    Should I use the DeploymentCatalogService on my custom ContentLoader –and on every class I need to access module-specific types?

    Thanks in advance,

    Raciel

    Friday, July 30, 2010 4:42 PM
  • Just found that the problem I'm having is due to how I'm loading the type with

    Type.GetType()

    when the target type is in a different assembly:

    http://blogs.msdn.com/b/haibo_luo/archive/2005/08/21/454213.aspx


    ... and not because of MEF...


    Since the only way I can load a type with Type.GetType is by specifying the assembly qualified name, and since I bet I won't have these details at runtime... I'm wondering what alternatives I have.

    Will take another look at the SL-MEF-Navigation Glenn made available a while ago, maybe the answer is there...


    Thanks,

    Raciel


    Friday, July 30, 2010 6:20 PM