More than one export was found that matches the constraint

When using MEF, you might one day find a class that is marked as export is not exported. Having a look at the trace window in VS, there is a line as:

More than one export was found that matches the constraint:
ContractName XXXX
RequiredTypeIdentity XXXX

Resulting in: Cannot set import ‘YYYY..ctor (Parameter=”operand1″, ContractName=”XXXX”)’ on part ‘YYYY’.

As the text suggested that there is more than one export of a class. There might be a genuine duplicated export if you try to export a type twice, but not in my case. I only declared it in one assembly.

The cause in my case is the assembly that has my export was deployed to more than one folders, and all those folders are scanned for import.

That alone does not cause more than one export complaint, it only happens when XXXX is a parameter by ImportingConstructor, in my example it is a parameter for YYYY.

Tags:

This entry was posted on Wednesday, October 31st, 2012 at 10:22 pm and is filed under ASP.NET. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “More than one export was found that matches the constraint”

  1. Martha says:

    We’re a group of volunteers and opening a brand new scheme in our community. Your site offered us with useful info to work on. You have done a formidable task and our whole community will be thankful to you.

Leave a Reply

*