1

When starting the application, which is bootstrapped with the MefBootstrapper from PRISM, I sometimes get a System.ComponentModel.Composition Warning. This is during the composition when there are problems loading some part. However the application still starts, but in an unpredictable state, since not all functions are available. Is there a way to make MEF throw an exception when this problem occurs so I can handle it as an error?

dymanoid
  • 14,771
  • 4
  • 36
  • 64
Richard Houltz
  • 1,962
  • 1
  • 18
  • 24

1 Answers1

1

Just pass a CompositionOptions.DisableSilentRejection value as the second parameter when you create your CompositionContainer:

var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);

Doing so, the (default) silent rejection will be disabled, so all rejections will result in errors.

More details, as usual, in MSDN.

dymanoid
  • 14,771
  • 4
  • 36
  • 64
  • I actually tried this while I was looking for the solution but MEF does not seem to respect that option. It still just gives a warning in the output window. Am I perhaps using the wrong version of MEF? – Richard Houltz Dec 22 '14 at 01:37
  • @RichardHoultz, what version are you using? This seems to work with System.ComponentModel.Composition.dll v4.0.30319 (.NET 4.5). – dymanoid Dec 22 '14 at 09:03