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

  • Home
  • SEARCH
  • 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 8689243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:35:47+00:00 2026-06-12T23:35:47+00:00

I keep getting the following error with the following code: Error: No exports were

  • 0

I keep getting the following error with the following code:

Error: "No exports were found that match the constraint: 

ContractName    MefTestSample.Contracts.ICanDoSomethingImportant"

Program.cs is as follows:

namespace MefTestSample
{
    class Program
    {
        private static CompositionContainer m_Container;


        static void Main(string[] args)
        {
            UseMockedUpTypes();
            ICanDoSomethingImportant cool = m_Container.GetExport<ICanDoSomethingImportant>().Value;
            cool.DoSomethingClever();
            Console.ReadLine();
        }

        private static void UseMockedUpTypes()
        {
            //The commented out section works just by itself.  
            /*
            m_Container =
                new CompositionContainer(
                    new AssemblyCatalog(
                        typeof(MefTestSample.Mocks.ClassesDoNotNecessarly).Assembly));
             */

            //This fails if i dont comment out the [ImportingConstructor] block.
            var assemblyCatalog1 = new AssemblyCatalog(typeof (MefTestSample.Mocks.ClassesDoNotNecessarly).Assembly);
            var myassembly = new AssemblyCatalog(typeof (ServiceLibrary.MoonService).Assembly);
            var aggregateCatalog = new AggregateCatalog(assemblyCatalog1, myassembly);
            m_Container = new CompositionContainer(aggregateCatalog);
        }
    }
}

Below is the code for ClassesDoNotNecessarly:

namespace MefTestSample.Mocks
{
    [Export(typeof(ICanDoSomethingImportant))]
    public class ClassesDoNotNecessarly : ICanDoSomethingImportant
    {
        //private IServicesContract _isc;
        #region ICanDoSomethingImportant Members

        /* This seems to be causing the problem.
        [ImportingConstructor]
        public ClassesDoNotNecessarly([Import("Moon")]IServicesContract isc)
        {
            string temp = isc.DisplayMessage();
            Console.WriteLine(temp);
        }
        */

        public void DoSomethingClever()
        {
            Console.WriteLine("Hehe, I'm actually procrastinating!");        
        }

        #endregion
    }
}

MoonService is as follows:

namespace ServiceLibrary
{
    [Export(typeof(IServicesContract))]
    public class MoonService : IServicesContract
    {
        public string DisplayMessage()
        {
            return "Moon services were accessed.";
        }
    }
}

What i believe the problem is. If i leave program.cs as it is, and comment out the [ImportingConstructor] attribute + constructor in the ClassesDoNotNecessarly class, the program will display the text in that class.

If i uncomment the [ImportingConstructor] attribute n constructor, i then start getting the error shown at the top of this question.

Any ideas would be appreciated.

  • 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-12T23:35:49+00:00Added an answer on June 12, 2026 at 11:35 pm

    Remove the [Import("Moon")] in the constructor, the Export is not named, so the Import cannot be named in return.

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

Sidebar

Related Questions

I'm trying to get http://www.gelens.org/code/gevent-websocket/ running and keep getting the following error. socket_id=1 already
I keep getting an error with the following bit of code. It is probably
With the following code, I keep getting error C2535 when I compile. It's complaining
Not sure what is wrong with this code. I keep getting the following error:
I keep getting the following error message when I run my code in debug.
I keep getting following error on this code: #Setup default variables $webUrl = Get-SPWeb
I'm running some code through JSHint and I keep getting the following error: Don't
I keep getting the following error: Method not found: 'Void Castle.MicroKernel.ComponentActivator.ComponentActivatorException..ctor this is from
I keep getting the following error Could not find a base address that matches
Why do I keep on getting the following error in this code in Visual

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.