Dynamic MEF isn’t thread safe by nature
this post focus a pitfall which you should be aware in order to avoid sporadic crashes.
In general most of MEF operation are operate once at the application initialization stage,
and it normally happens on a single thread.
this may not be true when you need to dynamically load MEF parts (using GetExportedValue or SatisfyImportsOnce).
unfortunately MEF underline is using non concurrent dictionary which is not thread safe for the above operation implementation.
therefore the following code will crash sporadically.
line 15: GetExportedValue call is a non protected critical section.
whenever using dynamic MEF techniques you should put a critical section synchronization over it.
the code sample can be found here.
Eran Stiller was the first one who’s point my intention to this issue.