Using the Reactive Extensions with the Silverlight Toolkit and MEF

Posted by Bobby Diaz on Geeks with Blogs See other posts from Geeks with Blogs or by Bobby Diaz
Published on Sun, 14 Mar 2010 05:12:32 GMT Indexed on 2010/03/14 5:25 UTC
Read the original article Hit count: 922

Filed under:

I have come across several instances of people having trouble using the new Reactive Extensions (v1.0.2317) in projects that reference the Silverlight Toolkit (Nov09) due to the fact that the original release of the Rx Framework (v1.0.0.0) was bundled with the Toolkit.  The trouble really becomes evident if you are using the Managed Extensibility Framework (MEF) to discover and compose portions of your application.
 

If you are using the CompositionInitializer, or any other mechanism that probes all of the loaded assemblies for valid exports, you will likely receive the following error:


Inspecting the LoaderExceptions property yields the following:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Reactive, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1b331ac6720247d9' or one of its dependencies. The system cannot find the file specified.  File name: 'System.Reactive, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1b331ac6720247d9'


This is due to some of the Toolkit assemblies referencing the older System.Reactive.dll.  I was able to work around the issue by bypassing the automatic probing of loaded assemblies and instead specified which assemblies my exports could be found.

    public MainPage()

    {

        InitializeComponent();

 

        // the following line causes a ReflectionTypeLoadException

        //CompositionInitializer.SatisfyImports(this);

 

        // skip the toolkit assemblies by specifying assemblies

        var catalog = new AssemblyCatalog(GetType().Assembly);

        var container = new CompositionContainer(catalog);

        container.ComposeParts(this);

 

        ShowReferences();

    }


With some simple xaml, I was able to print out exactly which libraries are currently loaded in the application.


You can download the sample project to run it for yourself!


Hope that helps!

© Geeks with Blogs or respective owner