I'm trying to debug an assembly import issue on a WPF app that uses MEF to load some plugins and looking for ideas to solve this particular exception:
<blockquote>
More than one export was found that matches the constraint:<br>
ContractName MarkPad.Contracts.ISpellingService<br>
RequiredTypeIdentity MarkPad.Contracts.ISpellingService
</blockquote>
There is only one assembly that references the plugin of concerndirectly as part of an autofac registration of it (code snippet at the very end).
There is only 1 implementation of
This is an open source <a href="https://github.com/Code52/DownmarkerWPF" rel="nofollow">Code52 project on github</a>.
The plugin import is:
<strong>What I've tried so far:</strong>
<ol>
<li><a href="http://marlongrech.wordpress.com/2010/05/03/mef-deploymentcatalog-and-reference-assemblies/" rel="nofollow">This</a> and <a href="http://geekswithblogs.net/abhijeetp/archive/2011/10/30/mef-101---part-2.aspx" rel="nofollow">this blog</a> post make reference to using
but that also doesn't seem to help. </li>
<li>Other discussions I found mention setting the 'Copy Local' to false, but because it's actually used in registration code that's not an option, as it doesn't end up in the output folder.</li>
</ol>
<strong>Any ideas?</strong>
The registration code referencing the plug-in
<blockquote>
More than one export was found that matches the constraint:<br>
ContractName MarkPad.Contracts.ISpellingService<br>
RequiredTypeIdentity MarkPad.Contracts.ISpellingService
</blockquote>
There is only one assembly that references the plugin of concerndirectly as part of an autofac registration of it (code snippet at the very end).
Code:
[ImportingConstructor]
public SpellCheckPlugin(
IPluginSettingsProvider settingsProvider,
ISpellingService spellingService,
ISpellCheckProviderFactory spellCheckProviderFactory)
There is only 1 implementation of
Code:
ISpellingService
Code:
[Export(typeof(ISpellingService))]
public class SpellingService : ISpellingService
This is an open source <a href="https://github.com/Code52/DownmarkerWPF" rel="nofollow">Code52 project on github</a>.
The plugin import is:
Code:
[ImportMany]
IEnumerable<IPlugin> plugins;
<strong>What I've tried so far:</strong>
<ol>
<li><a href="http://marlongrech.wordpress.com/2010/05/03/mef-deploymentcatalog-and-reference-assemblies/" rel="nofollow">This</a> and <a href="http://geekswithblogs.net/abhijeetp/archive/2011/10/30/mef-101---part-2.aspx" rel="nofollow">this blog</a> post make reference to using
Code:
[ImportMany(AllowRecomposition = true)]
<li>Other discussions I found mention setting the 'Copy Local' to false, but because it's actually used in registration code that's not an option, as it doesn't end up in the output folder.</li>
</ol>
<strong>Any ideas?</strong>
The registration code referencing the plug-in
Code:
builder.RegisterType<SpellingService>().As<ISpellingService>()
.SingleInstance()
.OnActivating(args =>
{
var settingsService = args.Context.Resolve<ISettingsProvider>();
var settings = settingsService.GetSettings<SpellCheckPlugin.SpellCheckPluginSettings>();
args.Instance.SetLanguage(settings.Language);
})