In a Visual Studio extension I'm trying to export a MEF component and find it later.
I have this class:
[Export(typeof(IBoilerplateSettings))]
public class BoilerplateSettings : IBoilerplateSettings
{
...
And this code to resolve in a callback from an OleMenuCommand. Got example from this pull request.
var componentModel = (IComponentModel)this.package.GetService(typeof(SComponentModel));
var settings = componentModel.DefaultExportProvider.GetExportedValue<IBoilerplateSettings>();
But it throws this error every time:
No exports were found that match the constraint:
ContractName UnitTestBoilerplate.IBoilerplateSettings
RequiredTypeIdentity UnitTestBoilerplate.IBoilerplateSettings
Both are in the same assembly. I've tried the [Export]
attribute in both System.Composition
and System.ComponentModel.Composition
but neither work.
I'm looking at the docs for MEF in VS but it sounds like adding the attribute should just work. I've also tried clearing the ComponentModel cache, but that didn't work. What am I missing here?
Generally two things to check:
And if that doesn't work, there's often the aggressive method which is to just break on all exceptions when Visual Studio is running, and see if you can find anything related to your extension. You might find some other loading exception, or some other root cause. Unfortunately that's a very scattershot approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With