How to avoid loading Silverlight Assemblies?

Oct 12, 2009 at 11:42 AM
Edited Oct 12, 2009 at 11:44 AM
I have a Silverlight web project and am using the following code to get the assemblies out of the ~/bin folder:
 			DirectoryCatalog directoryCatalog = new DirectoryCatalog(path);
			_compositionContainer = new CompositionContainer(directoryCatalog);

I have a method which I call which is below:

 

		public T[] GetPlugInsImplementing<T>()
		{
			return _compositionContainer.GetExportedValues<T>().ToArray();
		}

The problem is that I have Silverlight DLLs in the ~/bin folder. How can I avoid loading these DLLs, but load the server-side DLLs, as usual?

I get the exception:

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

with the LoaderException being:

{"Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.":"System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"}

Which refers to a Silverlight DLL. Am I right in assuming that this is the cause of the error?

 

 

 

 

 

 

 

 

DirectoryCatalog directoryCatalog = new DirectoryCatalog(path);
_compositionContainer = new CompositionContainer(directoryCatalog);

 

 

Developer
Oct 12, 2009 at 5:14 PM

There currently isn't any easy way to filter out Silverlight assemblies. That said you could enumerate the directory yourself and create a set of AssemblyCatalogs and put them in an AggregateCatalog, and do the filtering manually yourself.

As a side question why do you actually have loss Silverlight Assemblies in the bin directory? Typically they should be packaged up in a XAP and not sitting around as dll's.

Oct 12, 2009 at 5:40 PM

Thanks very much. Your solution will work assuming I know what assemblies are Silverlight assemblies. Is there a flag I can look for?

 

Interesting you raised the point about Silverlight DLLs being in the ~/bin folder. I assumed they get stuck in there when you refer to them in your References. My current ASP.NET Web Application Project (IWW.MIGTurbo2.ASPNET.Client) tree is:

 

 

Volume in drive D is DATA
 Volume Serial Number is FCF8-A955
 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\bin
12/10/2009  16:45            12,288 IWW.MIGTurbo2.ASPNET.Client.dll
12/10/2009  15:37           160,768 IWW.MIGTurbo2.ASPNET.dll
12/10/2009  15:37            63,488 IWW.MIGTurbo2.Client.dll
12/10/2009  15:37           267,264 IWW.MIGTurbo2.Core.dll
12/10/2009  16:45           252,928 IWW.MIGTurbo2.Silverlight.Core.dll
12/10/2009  15:39            16,384 IWW.MIGTurbo2.Silverlight.Server.dll
12/10/2009  15:37            77,824 IWW.MIGTurbo2.WCF.dll
27/08/2009  17:02           227,840 System.ComponentModel.Composition.dll
23/06/2009  22:12            75,640 System.ComponentModel.DataAnnotations.dll
23/06/2009  22:12            71,544 System.Windows.Controls.Data.Input.dll
23/06/2009  22:12            71,512 System.Windows.Data.dll
23/06/2009  22:12           124,752 System.Xml.Linq.dll
30/06/2009  16:51        13,949,952 Telerik.Web.UI.dll
02/10/2009  10:28           831,488 Telerik.Windows.Controls.dll
02/10/2009  10:28           286,720 Telerik.Windows.Controls.Docking.dll
02/10/2009  10:28           627,712 Telerik.Windows.Controls.GridView.dll
02/10/2009  10:28           520,192 Telerik.Windows.Controls.Input.dll
02/10/2009  10:28           749,568 Telerik.Windows.Controls.Navigation.dll
02/10/2009  10:28           237,056 Telerik.Windows.Data.dll
              19 File(s)     18,624,920 bytes
 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\bin\de
23/06/2009  22:12            18,336 System.ComponentModel.DataAnnotations.resources.dll
23/06/2009  22:12            38,792 System.Windows.Controls.Data.Input.resources.dll
23/06/2009  22:12            11,640 System.Windows.Data.resources.dll
23/06/2009  22:12            14,176 System.Xml.Linq.resources.dll
               4 File(s)         82,944 bytes
 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\bin\es
23/06/2009  22:12            17,824 System.ComponentModel.DataAnnotations.resources.dll
23/06/2009  22:12            38,792 System.Windows.Controls.Data.Input.resources.dll
23/06/2009  22:12            11,624 System.Windows.Data.resources.dll
23/06/2009  22:12            14,176 System.Xml.Linq.resources.dll
               4 File(s)         82,416 bytes
...
 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\ClientBin\extend
12/10/2009  15:39             9,216 IWW.MIGTurbo2.Silverlight.Contacts.dll
12/10/2009  16:45           252,928 IWW.MIGTurbo2.Silverlight.Core.dll
12/10/2009  15:39            25,088 IWW.MIGTurbo2.Silverlight.FogBugz.dll
               3 File(s)        287,232 bytes
 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\obj\Debug
12/10/2009  16:45            12,288 IWW.MIGTurbo2.ASPNET.Client.dll
               1 File(s)         12,288 byte

 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\bin

12/10/2009  16:45            12,288 IWW.MIGTurbo2.ASPNET.Client.dll

12/10/2009  15:37           160,768 IWW.MIGTurbo2.ASPNET.dll

12/10/2009  15:37            63,488 IWW.MIGTurbo2.Client.dll

12/10/2009  15:37           267,264 IWW.MIGTurbo2.Core.dll

12/10/2009  16:45           252,928 IWW.MIGTurbo2.Silverlight.Core.dll

12/10/2009  15:39            16,384 IWW.MIGTurbo2.Silverlight.Server.dll

12/10/2009  15:37            77,824 IWW.MIGTurbo2.WCF.dll

27/08/2009  17:02           227,840 System.ComponentModel.Composition.dll

23/06/2009  22:12            75,640 System.ComponentModel.DataAnnotations.dll

23/06/2009  22:12            71,544 System.Windows.Controls.Data.Input.dll

23/06/2009  22:12            71,512 System.Windows.Data.dll

23/06/2009  22:12           124,752 System.Xml.Linq.dll

30/06/2009  16:51        13,949,952 Telerik.Web.UI.dll

02/10/2009  10:28           831,488 Telerik.Windows.Controls.dll

02/10/2009  10:28           286,720 Telerik.Windows.Controls.Docking.dll

02/10/2009  10:28           627,712 Telerik.Windows.Controls.GridView.dll

02/10/2009  10:28           520,192 Telerik.Windows.Controls.Input.dll

02/10/2009  10:28           749,568 Telerik.Windows.Controls.Navigation.dll

02/10/2009  10:28           237,056 Telerik.Windows.Data.dll

 

 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\bin\de

23/06/2009  22:12            18,336 System.ComponentModel.DataAnnotations.resources.dll

23/06/2009  22:12            38,792 System.Windows.Controls.Data.Input.resources.dll

23/06/2009  22:12            11,640 System.Windows.Data.resources.dll

23/06/2009  22:12            14,176 System.Xml.Linq.resources.dll

 

 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\bin\es

23/06/2009  22:12            17,824 System.ComponentModel.DataAnnotations.resources.dll

23/06/2009  22:12            38,792 System.Windows.Controls.Data.Input.resources.dll

23/06/2009  22:12            11,624 System.Windows.Data.resources.dll

23/06/2009  22:12            14,176 System.Xml.Linq.resources.dll

               4 File(s)         82,416 bytes

...

 Directory of D:\dev2008\MIGTurbo2\IWW.MIGTurbo2.ASPNET.Client\obj\Debug

12/10/2009  16:45            12,288 IWW.MIGTurbo2.ASPNET.Client.dll

 

These files are then packaged up into the XAP, as far as I understand?

 

 

 

Developer
Oct 12, 2009 at 6:15 PM

The only thing that needs to be in the bin directory is the XAP file the Silverlight dlls do not need to be in there, perhaps you should just update your output directory for the Silverlight projects and simply put the XAP file in the bin directory.

Out of curiousity are you using MEF for both your Silverlight application and your ASP.Net application? It appears you have a mix of both.

As far as detecting the Silverlight assemblies, there really isn't a way that I know of because they are valid CLR 2.0 assemblies. If you really have to do this you could simply handle the exception when the AssemblyCatalog is created and skip the ones that blow up.

Oct 12, 2009 at 6:20 PM

Thanks for your help with this.

I'm new-ish to Silverlight development so maybe I've gone wrong somewhere.  I'll have a look at moving the SL DLLs out of the folder if they aren't supposed to be there.

Although I intend to use the Silverlight MEF code to manage plug-ins at the client-side of our project, this is not yet in place and any hint in this direction would indicate incorrect work on my part. At this time I am only playing with MEF at the server (ASP.NET and EXE-hosted based).