BennoDual
BennoDual

Reputation: 6259

Cannot getting object with MEF

I have three Assemblies

My Problem is now to register Context in MEF, that other instances can get it with IContext.

I have attached the Attribute [Export(typeof(IContext))] to Context. But when I now do this.Container.GetExportedValue<IContext>() I get a ImportCardinalityMismatchException.

The Constructor of Context is defined as follows

    [ImportingConstructor]
    public Context(IEventAggregator eventAggregator) { ... }

When I do this.Container.GetExportedValue<IEventAggregator>() for Testing to resolve the IEventAggregator, this is working.

Can somebody help me, what I am doing wrong? - Does I have to attach somewhere the AssemblyX and/or AssemblyY?

Thanks. Thomas

Upvotes: 1

Views: 2472

Answers (2)

Daniel Plaisted
Daniel Plaisted

Reputation: 16744

Are all three of the assemblies in the catalog MEF is using?

If that's not the issue, have a look at my blog post on How to Debug and Diagnose MEF failures.

Upvotes: 0

andrew
andrew

Reputation: 1030

To resolve IContext(as Context from the assemblyY), the Container has to be aware of AssemblyY(that is, about all composable parts from it). In order to it, you should use the appropriate catalog. Or in case if AssemblyY is loaded on demand, it should be loaded before the Context is used.

Upvotes: 3

Related Questions