Geeks With Blogs
bobby's blog randomly specific...

I have come across several instances of people having trouble using the new Reactive Extensions (v1.0.2.5) 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.
 

Update:  After getting some feedback in the comments, I was able to find a solution for the type load exception that works along with the DragDrop class of the Silverlight Toolkit!  The key is to load both versions of the System.Reactive.dll into the application.  You can't do it via the standard Add Reference, but the following code illustrates how it can be done:

    public MainPage()

    {

        // force previous version to be loaded

        var part = new AssemblyPart() { Source = "References/System.Reactive.v1.0.0.0.dll" };

        Deployment.Current.Parts.Add(part);

        LoadReferences();

 

        InitializeComponent();

 

 

        // this works now!

        CompositionInitializer.SatisfyImports(this);

        References.ItemsSource = references;

    }

The updated source code includes the previous dll in the Silverlight project as Content.  End Update.


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!

Posted on Saturday, March 13, 2010 11:12 PM Silverlight , Reactive , MEF | Back to top


Comments on this post: Using the Reactive Extensions with the Silverlight Toolkit and MEF

# re: Using the Reactive Extensions with the Silverlight Toolkit and MEF
Requesting Gravatar...
Hi Bobby

Nifty tool Bobby.

You can also override the default catalogs / container used by CompositionInitializer which will achieve the same result. In your app call CompositionHost.Initialize passing in either catalogs or a pre-configured container.
Left by Glenn Block on Mar 13, 2010 11:30 PM

# re: Using the Reactive Extensions with the Silverlight Toolkit and MEF
Requesting Gravatar...
Hi Bobby.

I'm having the same problem.

Unfortunately your solution does not really work.
Try pasting the following line in your MainPage and you'll notice you'll get an assembly load exception:

Microsoft.Windows.DragDrop.DoDragDrop(this, null, Microsoft.Windows.DragDropEffects.All, Microsoft.Windows.DragDropKeyStates.AltKey);
Left by clement on Mar 14, 2010 12:31 AM

# re: Using the Reactive Extensions with the Silverlight Toolkit and MEF
Requesting Gravatar...
@Glenn, thanks for the tip!

@Clement, I found a way to get the drag drop to work. I have updated the source code to include a ListBoxDragDropTarget in the MainPage.xaml.

Take a look and let me know if that works for you!

Thanks,
Bobby
Left by Bobby Diaz on Mar 14, 2010 3:13 AM

# re: Using the Reactive Extensions with the Silverlight Toolkit and MEF
Requesting Gravatar...
Works like charm. Nice one Bobby.
Left by clement on Mar 14, 2010 6:18 AM

# re: Using the Reactive Extensions with the Silverlight Toolkit and MEF
Requesting Gravatar...
Hi it works! Thanks alot you saved me.

Btw is microsoft aware of this issue?
Left by Tendious on Apr 04, 2010 4:34 PM

# re: Using the Reactive Extensions with the Silverlight Toolkit and MEF
Requesting Gravatar...
From what I've read, the next release of the Silverlight Toolkit will not have the issue since it will use the latest version of the Rx Framework. It should be coming out around the same time as Silverlight 4 RTM (April 12th).
Left by Bobby Diaz on Apr 05, 2010 4:42 PM

# re: Using the Reactive Extensions with the Silverlight Toolkit and MEF
Requesting Gravatar...
Bobby,

This was a great find. The April 2010 release of the toolkit also solves the problem by not including the reactive framework per your comment. I tested my app, had the problem with the earlier toolkit, was fixed with your methods, went to the April toolkit, and no longer needed the workarounds.
Left by Mark Stega on May 05, 2010 3:04 PM

Your comment:
 (will show your gravatar)


Copyright © Bobby Diaz | Powered by: GeeksWithBlogs.net