This project has moved and is read-only. For the latest updates, please go here.

Import contract from a signed assembly in different versions

Jan 1, 2009 at 8:31 AM

I am having trouble to import a type that has a contract in a signed assembly.
The exporter assembly and the importer assembly are both referencing a signed assembly that contains the contract,
but the each one is using a different version.

This is the error message:
An unhanded exception of type 'System.ComponentModel.Composition.CompositionException' occurred in System.ComponentModel.Composition.dll

Am I doing something wrong? or this is a bug?

Detailed explanation:
1. The assembly that contains the Export attribute is referencing another, signed, assembly in version, that contains the contract ("IMyContract1").
2. The assembly that contains the Import attribute is referencing the same assembly that contains the contract., but in version
3. If the contract assembly is not signed everything is ok.

Exporter code:
public class MyClass1 : IMyContract1
    public int MyProperty { get; set; }

Importer code:







Assembly assembly = Assembly.LoadFrom(@"Path to exporter ...");
AttributedAssemblyPartCatalog catalog = new AttributedAssemblyPartCatalog(assembly);
CompositionContainer container = new CompositionContainer(catalog);



public IMyContract1 MyContract { get; set; }


Jan 16, 2009 at 11:54 PM
It might help to see what the CompositionException is actually saying is wrong, however, you are likely encountering a CompositionException because V1 and V2 of IMyContract1 are actually considered as two different types by the CLR, and therefore, are not considered assignable to each other. MEF has the same versioning restrictions that the CLR loader provides.

If you do want them to be considered the same, you need to add binding redirects in your App.config to redirect from Assembly v1 -> Assembly v2.

Jan 22, 2009 at 7:07 AM
Yes they are considered as two different types by the CLR, but I kind of counted on MEF to do the duck typing.

10x for your answer!
Jan 22, 2009 at 4:46 PM
Although earlier versions of MEF shipped with duck typing, the latest versions do not.