Dependency between modules and 3th party libs

Topics: Prism v4 - Silverlight 4
Apr 6, 2011 at 4:58 PM
Edited Apr 6, 2011 at 5:00 PM
Hi guys,
I faced very strange problem.
Prism application has 1 Class Library project
 - MyLibrary project, which has MyBaseClass.cs
and 2 modules:
 - MyLibsModule (consist MyLibrary.dll).
 - MyModule which depends on MyLibsModule (dependency set in ModuleCatalog.xaml).
So Idea is to have module with dll's and separate MyLibrary.dll from other modules.
Now, MyModule project has a helper class which overrides MyBaseClass class defined in MyLibrary.
In MyModule I refer MyLibrary project and set CopyLocal=false, as dependency MyLibsModule has it.

Problem is that MyModule fails initializing/constructing if MyLibrary.dll is set to CopyLocal=false.

If I remove helper class (or remove inheritance from class defined in MyLibsModule), everything is working fine.
If I set CopyLocal=true for mydll.dll  in MyModule, it works fine as well. But I don't want to set copyLocal=true, as dependency Module MyLibsModule has this dll, and I don't need duplicate.
Any ideas?
How come that MyModule fails with complain abt missed MyLibrary.dll if even constructor is not called in it.
I expect sequence of events like this:
1. MyLibsModule.xaml, MyModule.xaml downloaded from server,
2. MyLibsModule constructor called.
3. MyLibsModule imported.
4. MyLibsModule initialized.
Exception here....
5. MyModule constructor called,
6. MyModule imported.
7. MyModule initialized.
 
If MyModule is loaded with Shell (InitializationMode="WhenAvailable", which is equal to referencing MyLibrary.dll at compile time) then MyModule is loading no problem. I want all modules loaded on demand...-))

I have demo project to show this....Initially I asked support from Telerik here:http://www.telerik.com/community/forums/silverlight/general-discussions/telerik-libs-prism-app.aspx , but obviously it is related to Prism.....
Apr 6, 2011 at 6:40 PM

Hi,

Before digging into your issue, it would be helpful to know that the recommended practice for having a third party class library shared across your modules is to have an infrastructure project referenced in all your modules. Modules are mostly meant to be discrete units of functionality that export views and/or services.

As for your actual issue, the problem you’re experiencing could be caused by the fact that your module isn’t finding the dll which contains the classes you need to use. One possible way to solve it would be to reference the infrastructure project in your shell module with CopyLocal set to true; that way you could then reference that project from within other projects without the need to set CopyLocal to true, since the dll will have already been loaded in the shell’s bin directory. That way you would avoid a duplicate reference.

I hope you find this information useful.

Thanks,

Miguel Bronzovic
http://blogs.southworks.net/mbronzovic

 

Apr 6, 2011 at 6:53 PM

Yes, this is what I ended up with..

I see  2 options either load infrastructure dlls into shell as static link, as u suggest or equally the same is to loas MyLibsModule in WhenAvailable mode.

but I want to make shell as light as possible and as fast as possible, thats why I tried to move havy dlls into another module. Reason for this that shell may not need havy dll module and MyModule, so no point to load it.. u see what i mean?
But anyway it is still not clear for me, how come MyModule is failing if it even didn't started to load.

Dependency modules loaded, as I see from step 4, so everything should be available for MyModule..

Apr 8, 2011 at 7:04 PM

Hi,

We've reproduced a similar scenario and didn't experience the problem you're mentioning. In this context, it would be helpful if you could provide us with a repro sample, so that we can help you further understand the root of this unexpected behavior.

Miguel Bronzovic
http://blogs.southworks.net/mbronzovic

 

Apr 9, 2011 at 11:28 AM

OK, I can upload demo project... Where to? What's address?

When you experiment with your project, pls make sure that everytime you load shell, your browser cache is clean..Otherwise there is chance that module's dependency is in cache... Also make you MyLibsModule bigger (put some stuff in it) to emulate longer download time then MyModule.

Developer
Apr 11, 2011 at 4:40 PM

Hi,

You could upload it to SkyDrive or a similar site. Thank you for the additional information.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Apr 12, 2011 at 1:08 PM

Here is url: http://cid-17feeb61afe2dbeb.office.live.com/self.aspx/.Documents/PrismExample/PrismExample.rar

So, solution has 2 Modules and 1 class Lib.

MyModule depends on MyLibsModule, which has MyService.dll.
MyModule overrides MyService.MyBaseClass and has MyService copyLocal=false.

To repeate problem, run application, make sure that browser cache is clean and click Load Module Btn.. Try few times...exception should be thrown.

Now either set MyService copyLocal=true in MyModule or remove inheritance in MyModule.Helpers.MyClass.. Exception never thrown.

and now explain me why MyModule is constructing if dependency is not loaded...

 

Developer
Apr 12, 2011 at 3:28 PM
Edited Apr 12, 2011 at 3:29 PM

Hi,

We've been able to reproduce the issue you're mentioning using your sample application.

We've found a similar issue reported on this thread and its associated work item:

As a workaround, you could stick to setting Copy-Local to true in the dependency to MyService.

Thanks,

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Apr 12, 2011 at 3:42 PM

Does it mean that this will be considered as a bug of the framework and eventually will be fixed.

BTW, Guido, are you prism project developer?