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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:21:21+00:00 2026-05-19T05:21:21+00:00

I think I am losing my mind. :) I’ve been struggling with this for

  • 0

I think I am losing my mind. 🙂
I’ve been struggling with this for two days now. The code looks right. But for some reason when I try to access the [ImportMany] field, it is null, or at least not returning any values.

It get the 3 parts in the catalog, but they don’t get applied to the Lazy[] import I am defining.

Here’s my code:

using System;
using System.Linq;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;

namespace MefTest
{

// Extension interface and metadata

    public interface IUIExtension
    {
       void DoSomething();
    }

    public interface IUIExtensionDetails
    {
        string Name { get; }
        string Uri { get; }
    }

    [MetadataAttribute]
    [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
    public class UIExtensionAttribute : ExportAttribute
    {
        public UIExtensionAttribute() : base(typeof(IUIExtensionDetails)) { }

        public string Name { get; set; }
        public string Uri { get; set; }
    }

        // Extensions

    [UIExtension(Name="Test 01", Uri="http://www.yourmomma.com/")]
    public class Test1Extension : IUIExtension
    {
        public void DoSomething() { }
    }

    [UIExtension(Name = "Test 02", Uri = "http://www.yourdaddy.com/")]
    public class Test2Extension : IUIExtension
    {
        public void DoSomething() { }
    }

    [UIExtension(Name = "Test 03", Uri = "http://www.youruncle.com/")]
    public class Test3Extension : IUIExtension
    {
        public void DoSomething() { }
    }

        // Main program

    public class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            p.Run();
        }

        [ImportMany]
        public Lazy<IUIExtension, IUIExtensionDetails>[] Senders { get; set; }

        public void Run()
        {
            Compose();
        }

        public void Compose()
        {
            var catalog =  new AssemblyCatalog(
                System.Reflection.Assembly.GetExecutingAssembly());
            var container = new CompositionContainer(catalog);

            container.ComposeParts(this);

            // This is always 3
            Console.WriteLine(
                (from g in container.Catalog.Parts select g).Count());
            // This is always 0
            Console.WriteLine(Senders.Length);

            Console.ReadKey();
        }
    }

}
  • 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-05-19T05:21:22+00:00Added an answer on May 19, 2026 at 5:21 am

    Your metadata attribute is defining the exports as typeof(IUIExtensionDetails) which is your metadata contract, not your actual extension. Change the custom attribute constructor to:

    public UIExtensionAttribute() : base(typeof(IUIExtension)) { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I'm losing my mind here. This is the code. (It's a simplified
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want
I think I have a basic understanding of this, but am hoping that someone
I've a nice situation, I think at beginning this a usual query but I'm
This is a follow-up question to this question because I'm losing my mind over
OK, I'm losing my mind over this. I did read here at SO and
Okay, I'm losing my mind over this one. I have a method in my
I think I'm losing it, can anyone explain why am I experiencing the following:
Think about doing this: import matplotlib.pyplot as plt plt.plot(x_A,y_A,'g--') plt.plot(x_B,y_B,'r-o') plt.show() How would you
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I

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.