views:

44

answers:

1

I have a class with an IList<T> property decorated with the [ImportMany(allowRecomposition = true)] attribute. There are some conditions in which the application might not find any available Exports of the requested type. Right now, it's throwing a CompositionException if no Exports of the requested type are found. I dislike application flow being determined by thrown exceptions, so I would rather not catch and react in this case. Rather, I just want program execution to continue.

Is there a flag or something I can set to make this Import optional? I know for single import properties, you can do this: [Import(AllowDefault = true)] but 'AllowDefault' is not an option on the ImportMany attribute.

+2  A: 

There most be something else failing because by definition ImportMany will allow zero or more items, so if there isn't a value it will not cause any errors.

Wes Haggard
You're exactly right. It was something else causing the error. Thanks for your time on this.
Kilhoffer