tags:

views:

41

answers:

2

I am developing a host application using Managed Extensibility Framework and it's built against .NET 4 and the System.ComponentModel.Composition assembly that is built into the framework. I would like to support the ability to develop parts using .NET 3.5 and export them declaratively.

Since the export attributes are new in .NET 4 and thus cannot be referenced by the .NET 3.5 assembly, I'm not sure the best way to go about exporting parts. Is there an easy way to do this without implementing a new type of catalog that uses some other mechanism for discovering exports?

A: 

You might be able to use an Assembly Binding Redirect to have the extensions compiled against a .NET 3.5 version of MEF but have them use the .NET 4 version at runtime.

Daniel Plaisted
Good suggestion but unfortunately the 3.5 version of MEF was released through CodePlex and so it has a different public key token. Assembly redirection will only redirect version numbers as far as I know.
Josh Einstein
+1  A: 

You can write a handler for AppDomain.AssemblyResolve that will return the .NET 4 version of MEF when the 3.5 version is requested. However, the handler you write will only be used if it can't find the assembly using the default binding logic, so you would need to make sure the 3.5 MEF DLL wasn't available, or possibly load the extension assemblies with no context (see here) to prevent it from resolving to that DLL.

Daniel Plaisted
Sorry for the delay in responding. I got around to testing this and it actually works. It's unfortunate that they couldn't find a way to sign it with the same key so they could just redirect it with publisher policy but that's life I guess.
Josh Einstein