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 8454065
In Process

The Archive Base Latest Questions

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

We were using MEF Contrib open generics support like this: [InheritedExport] interface ITest2<T> {

  • 0

We were using MEF Contrib open generics support like this:

[InheritedExport]
interface ITest2<T>
{
    void Execute();
}

class TestClass2<T> : ITest2<T>
{
    public void Execute()
    {
        Console.WriteLine();
    }
}

class Program
{
    static void Main(string[] args)
    {
        var catalog = new AssemblyCatalog(typeof(Program).Assembly);
        var container = new CompositionContainer(catalog);
        var test2 = container.GetExportedValues<ITest2<string>>();
    }
}

However, since the installation of .NET Framework 4.5, this code no longer works. Not only does it no longer work after building against .NET 4.5, or .NET 4.0, but it also breaks existing compiled applications.

It appears that one has to either use an explicit [Export(typeof(ITest2<>))] attribute on TestClass2, or to change the definition:

[InheritedExport(typeof(ITest2<>))]
interface ITest2<T>
{
    void Execute();
}

Does anyone know why this has changed? Curiously, MEF’s open generics support (in 4.5) also fails with a non-typed [InheritedExport] attribute on an open generic interface.

I would have thought that the default behaviour for [InheritedExport] on an open generic interface would be the same as [InheritedExport(typeof(ITest2<>))].

Thanks,
Steve

  • 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-10T11:55:37+00:00Added an answer on June 10, 2026 at 11:55 am

    This is a bug in the .Net 4.5 MEF implementation of Open Generics support. It will be fixed in the next release of .Net framework.

    There are a couple of work arounds none of them ideal.

    1. Make the interface an abstract base class
    2. Remove the InheritedExport from the interface and explicitly mark the derived classes with the Export Attribute.

    I hope this helps.

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

Sidebar

Related Questions

I'm using MEF for a plugin-system to my application. The flow goes like this:
I have a generics class, that uses TBase as the type parameter. Using MEF,
I'm using MEF to create several instances of the same export. I'd like to
I have IMessageSender interface. using System.ComponentModel.Composition; public interface IMessageSender { void Send(string message); }
I'm using MEF as an IoC container. If the requesting class is in the
I am using MEF to do a sort of crude plugin architecture. This is
I'm using mef to create WCF web services. This is how service looks: [Export]
I've been successfully using MEF to obtain exported class instances. However, I came across
I'm using MEF to allow users to extend my C# library. It's working great
I am using MEF in Silverlight for dynamic download .xap file. I want to

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.