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

Cannot call SatisfyImports on a object of type 'xx' because it is marked with one or more ExportAttributes.

Apr 23, 2010 at 6:49 PM

Hi People,

I have application which shows widgets downloaded dynamically from web like this

var catalog1 = new DeploymentCatalog("FormSubmitter_Widget.xap" );
var aggregate = new AggregateCatalog (catalog1);
CompositionHost.Initialize(new DeploymentCatalog (), aggregate);

It works fine till I convert FormSubmitter_Widget into MEF type widget - basically my  exported widget is built from imported parts of type Country..

This is what I mean

public partial class CountrieBrowser_Widget : UserControl, IWidget
   public CountrieBrowser_Widget(){
public List<Country> Countries { get; set; }

Coutries classes have [export] attributes...

And this doesn't work. Error in constructor during SatisfyImports(this) call.

If I comment out CompositionInitializer.SatisfyImports(this) in  CountrieBrowser_Widget() constructor - no errors and no values in Countries property.


What I do wrong?


Apr 23, 2010 at 8:28 PM
Edited Apr 23, 2010 at 8:37 PM

You only need "CompositionInitializer.SatisfyImports(this);" if the object is not created by the MEF container. I'm not very familiar with silverlight but I assume this is the case for objects that are created by loading XAML. 

However, you also have "[WidgetExport(typeof(IWidget))]" on your class. The export attribute shows your intention to let the object be created by the MEF container.

The SatisfyImports error is telling you that you can either use SatisfyImports or an Export attribute. But using both doesn't make sense.

Apr 23, 2010 at 11:13 PM

ok. Agree.

Then how to initialaze properties of the object B via MEF if this object is being exported as well.

class A{
 public A(){CompositionInitializer.SatisfyImports(this);}
 B PropertyA{get;set;}

class B{
public B(){CompositionInitializer.SatisfyImports(this);}
 C PropertyB{get;set;}

class C{
blah blah..

I think constructor of class B should SatisfyImport and initialize PropertyB? Or constructor of class A should do all magic?

Apr 24, 2010 at 12:15 AM

Looks like I found bug.

I exported class C as [Export] and in class B PropertyB was empty...

If I export class C as [Export(typeof(someinterface)] everything is working fine.

Now question is why just [Export] doesn't do magic - import in class B should import all types B being exported.. -))

Brrr... I am confused.

Dec 22, 2012 at 12:42 PM

You only need to call  SatisfyImports once then use the "GetExportedValue" to new up the types from the container


I know this is quite an old post but its nice to have questions wrapped up.