Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:55:48+00:00 2026-06-10T06:55:48+00:00

I got a CompositionContractMistachException when using a custom attribute class in MEF on .NET

  • 0

I got a CompositionContractMistachException when using a custom attribute class in MEF on .NET 4.0.

Unable to create an instance of the Metadata view '(snip).ModuleExportAttribute, (snip), Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because a constructor could not be selected. Ensure that the type implements a constructor which takes an argument of type IDictionary<string, object>.

Here is my ModuleExportAttribute class, nothing special:

[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class ModuleExportAttribute : ExportAttribute
{
    public ModuleExportAttribute(string name) : base(typeof(IModule))
    {
        this.Name = name;
    }

    public string Name { get; private set; }
}

The usage is like this:

[ModuleExport("MyModule")]
public class MyModule : IModule
{ 
   ...
}

After adding the asked constructor, the exception goes away.

However, I couldn’t find any reference that states this requirement. On the opposite, I saw many examples and blog posts using custom attribute class without such constructor. Am I missing something here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:55:50+00:00Added an answer on June 10, 2026 at 6:55 am

    How are you trying to import this? I suspect the error is caused by you importing something like Lazy<IModule, MetadataExportAttribute> in which case yes in order to use a concrete type as the metadata type it must either be an interface, in which case we generate a proxy type or it must be a type that takes an IDictionary<string,object> so that the metadata can be passed to it.

    Try something like:

    public interface IModuleMetadata
    {
      string Name { get; }
    }
    

    Then change your import to something like:

    [Import]
    Lazy<IModule, IModuleMetadata> Module;
    

    I also like to have my ExportAttribute implement the IModuleMetadata interface to make sure they stay consistent but that isn’t absolutely necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got this error while trying to get the variables out of a class. Using
Got a little problem. I'd like to create an android list view activity with
Got some incomprehensible exercise in my book. Create a class with a non-default constructor
Got this error message while trying to load view: The model item passed into
Got a list saved by using .data(). How is it possible to find exact
Got a working AJAX form: @using (Ajax.BeginForm(...)) I want to disable the button while
Got this: http://jsfiddle.net/NdsF8/ Want it to be dynamic so when you click a new
Got a class that serializes into xml with XMLEncoder nicely with all the variables
Got a problem with ADOMD.NET 8.0, SQL2008 and our app. It isn't giving us
Got this error when parsing my html page using XPATH.. i am also using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.