Getting more information from the CompositionException
As you are working yourself through the Managed Extensibility Framework, you’re likely to hit a CompositionException with an error similar to the following:
System.ComponentModel.Composition.CompositionException: There was at least one composition issue of severity level `error'. Review the Issues collection for detailed information.
Unfortunately, the default error message is in itself, lacking any real information, requiring you to look at the CompositionException.Issues collection to get anything useful.
To ease this, try using the following method to return a better error message as your playing around with the composition engine:
private static string GetFriendlyCompositionFailure(CompositionException exception)
{
StringBuilder builder = new StringBuilder();
builder.Append(exception.Message);
foreach (CompositionIssue issue in exception.Issues)
{
builder.AppendLine();
builder.AppendFormat("{0} : {1} : {2}", issue.Severity, issue.Id, issue.Description);
if (issue.Exception != null)
{
builder.AppendFormat("\t{0}: {1}", exception.GetType(), exception.Message);
}
foreach (var pair in issue.Details)
{
builder.AppendFormat("\t{0} : {1}", pair.Key, pair.Value);
}
}
return builder.ToString();
}
This turns the above message into the much more useful:
System.ComponentModel.Composition.CompositionException: There was at least one composition issue of severity level `error'. Review the Issues collection for detailed information.
Error : CM: NoExportsThatMatchContract : There were no exports found with the contract 'IConfigurationStore'.
Error : CM: ImportFailedDetailsInPreviousFailures : A failure occurred while trying to satisfy member 'Store' on type 'ConfigurationService' while trying to import value 'IConfigurationStore'. Please review previous issues for details about the failure.
Hopefully, the error message is something we can get improved by the next CTP.