PartCreator<T> Problems

Oct 26, 2009 at 6:31 PM

This works:
[Import]
Lazy<IFoo> foo;

But this throws an exception:
[Import]
PartCreator<IFoo> fooCreator;

 

What am I missing?

//lasse

Developer
Oct 26, 2009 at 6:40 PM

Which version of MEF are you using here? PartCreator is currently only available in the Siverlight version of MEF, support for it didn't make it into the .Net 4.0 version of MEF. Although it is interesting that PartCreator<IFoo> even compiled for you I wonder if there was a mix-up in the latest preview of MEF.

Oct 26, 2009 at 8:26 PM

Hi

I downloaded MEF_Pre_beta_2.zip.

//lasse

Developer
Oct 26, 2009 at 9:39 PM

Does your sample have a reference to the DynamicInstantiation project that is contained in the Samples? If it doesn't then I wouldn't expect it to even compile. But if you do and you want to use it then you would need something like:

var catalog = new AggregateCatalog(new AssemblyCatalog(typeof(Program).Assembly));
var dynamicInstantiationProvider = new DynamicInstantiationExportProvider();
var container = new CompositionContainer(catalog, dynamicInstantiationProvider);

Which would allow you to use PartCreator on MEF for .Net 3.5/4.0.

Oct 27, 2009 at 8:09 AM

Thanks,, that did it.

Now it works, and yes, I had added a reference to the dll fromDynamicInstantiation project, otherwise it would not compile.

( Maby its me (otften me according to my wife) but the documentation is not so clear about this and the difference between Codeplex/mef and the different versions that seems to exists. :)  )

//lasse