Loading modules ondemand

Topics: CAB & Smart Client Software Factory
Oct 25, 2005 at 7:22 AM
originally posted by: Teddy_Cineas

If you an application with more than 20 modules and you don't want to load them using the profilecatalog, what's the best way to load module ondemand?
Dec 2, 2005 at 7:18 PM
originally posted by: headlam

Teddy, you can dymanically load modle using code similar to the following

// load the assembly (or assemblies)
Assembly[] a = new Assembly1;
a0 = Assembly.LoadFile(@"C:\Temp\MyModule2.dll");

// get a reference to the module loader service
IModuleLoaderService svc = ParentWorkItem.Services.Get<IModuleLoaderService>(true);

// load the assembly or assemblies dynamically
svc.Load(ParentWorkItem.RootWorkItem, a);

Hope that helps.
Dec 3, 2005 at 6:33 AM
originally posted by: BradWilsonMSFT

You don't even need to make an array. The parameter is marked with "params", so you can pass 0..n assembly objects to it, comma separated:

Assembly a = Assembly.LoadFile(@"C:\Temp\MyModule2.dll");
IModuleLoaderService svc = ParentWorkItem.Services.Get<IModuleLoaderService>(true);
svc.Load(ParentWorkItem.RootWorkItem, a);

or even:

Assembly a1 = Assembly.LoadFile(@"C:\Temp\MyModule2.dll");
Assembly a2 = Assembly.LoadFile(@"C:\Temp\MyModule3.dll");
Assembly a3 = Assembly.LoadFile(@"C:\Temp\MyModule4.dll");
IModuleLoaderService svc = ParentWorkItem.Services.Get<IModuleLoaderService>(true);
svc.Load(ParentWorkItem.RootWorkItem, a1, a2, a3);
Dec 14, 2005 at 4:15 AM
originally posted by: Hanoulle

Can I use the ProfileCatalog.xml to load modules from another folder?

When I give a full path to an assembly the application loads, but he does not load the module.
Dec 23, 2005 at 7:35 PM
originally posted by: Teddy_Cineas

Thanks
Feb 15, 2006 at 6:46 AM
originally posted by: Simon_Natanel

Hi,

First, I would like to know where this code should be used (which module/file).
Second I would like to know if this solution fits my following problem:
I have show interactions and each interaction is implemented as an assembly. The assembly should know how to show an interaction and save a new interaction. The assemblies can be downloaded automatically to a folder my program has to handle all the assemblies when first loaded (without knowing about the specific implementation). I've been studying cab mainly for the loading abbilities. I won't have messages between modules but have messages between the shell and the module. Should I use a workspace, smartpart etc. ?

I know it's a long question but would be happy for a reply.

Simon
Mar 28, 2006 at 11:17 PM
originally posted by: ching100

to headlam:

Why I got an error of this line:
IModuleLoaderService svc = ParentWorkItem.Services.Get(true);
----No method of Get takes 1 parameter: Get( Type serviceType, bool ensureExists);
----Can't convert object to IModuleLoaderService ;

Could you help me ? or gives me a sample code.
Thanks in advence
Apr 13, 2006 at 12:53 PM
originally posted by: a_pros

In string:
IModuleLoaderService svc = ParentWorkItem.Services.Get(true);
after word "Get" you must include "IModuleLoaderService" as Generic's argument, but in this message board this expression's argument dissappear to some place.
See full code on VB.NET:
Dim a As Assembly = Assembly.LoadFile(My.Computer.FileSystem.CurrentDirectory & "\MyModule2.dll")
Dim svc As IModuleLoaderService = Me.Parent.Services.Get(Of IModuleLoaderService)(True)
svc.Load(Me.Parent.RootWorkItem, a)
Some comments:
- This code is placing in another module, which trying load an assembly;
- You must include in your file some reference, see below on C#:
using Microsoft.Practices.CompositeUI.Services;
using System.Reflection;
Apr 13, 2006 at 2:36 PM
originally posted by: davidlaribee

For what it's worth, you can express generics in posted code thusly:

&amplt = &lt
&ampgt = &gt

For some reason you need to leave off semi-colons when representing escape sequences...
Aug 25, 2006 at 2:44 AM
originally posted by: cpearson

Where abouts would your code go, in ShellForm? How do I access ParentWorkItem?
Sep 12, 2006 at 9:37 AM
originally posted by: zwzhang28

Hi,

Following code works. My question is what happened when the IModuleLoaderService.Load is called more than once on a same assembly?

Since Assembly.Load ensures the dll is loaded only once. But I am not sure about the IModuleLoaderService.Load
Do we need to use a bool flag to avoid calling IModuleLoaderService.Load more than once on the same assembly?

try
{
Assembly a = Assembly.Load("AModule");
IModuleLoaderService svc = this.WorkItem.Services.Get<IModuleLoaderService>(true);
svc.Load(this.WorkItem.RootWorkItem, a);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}


Thanks a lot.
Sep 12, 2006 at 9:46 AM
originally posted by: zwzhang28

Hi,

About my above post.

By monitering IModuleLoaderService.LoadedModules, following call the posted code few times. I found the module was loaded only once.


Thanks