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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:01:30+00:00 2026-05-29T05:01:30+00:00

I would like to retrieve an enumeration of instantiated classes that implement an interface

  • 0

I would like to retrieve an enumeration of instantiated classes that implement an interface from across several assemblies within a solution folder.

I have a the following folder structure (if this makes sense):

Solution
   -SolutionFolder
      - Project1
          - class implementing interface I would like to find
          - other classes

      - Project2
          - class implementing interface I would like to find
          - other classes

   -MainProject
      - classes where my code is running in which I would like to retrieve the list of classes

Therefore, if the interface being implemented is ISettings, then I would like an IEnumerable<ISettings> referencing instantiated objects of that interface.

So far, I have used reflection to retrieve the classes that implement the interface from a known class name:

IEnumerable<ISettings> configuration = 
                (from t in Assembly.GetAssembly(typeof(CLASSNAME-THAT-IMPLEMENTs-INTERFACE-HERE)).GetTypes()
                 where t.GetInterfaces().Contains(typeof(ISettings)) && t.GetConstructor(Type.EmptyTypes) != null
                 select (ISettings)Activator.CreateInstance(t)).ToList();

but this is a single assembly and I will not actually know the class names.

Can this be achieved using reflection or does it require something more?

  • 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-29T05:01:33+00:00Added an answer on May 29, 2026 at 5:01 am

    To resolve this issue, I set the post build event of the each project in the solution folder to copy its assembly to the bin folder in the main projects bin folder.

    The post build event was set similar to:

    copy "$(TargetPath)" "$(SolutionDir)MainProjectName\bin"
    

    Then I used the following to retrieve the assembly file names from this bin directory (credit to Darin for his solution post here):

    string[] assemblyFiles = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"), "*.dll");
    

    Then I retrieved implementations of the objects implementing the interface ISettings using:

    IEnumerable<ISettings> configuration = assemblyFiles.Select(f => Assembly.LoadFrom(f))
                    .SelectMany(a => a.GetTypes())
                    .Where(t => t.GetInterfaces().Contains(typeof(ISettings)) && t.GetConstructor(Type.EmptyTypes) != null)
                    .Select(t => (ISettings)Activator.CreateInstance(t));
    

    This allows me to add further projects that implement settings without recompiling the main project.

    Additionally, one alternative I looked at was to use MEF where an introduction can be found here.

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

Sidebar

Related Questions

I would like to retrieve articles that are within 1 year from the today's
I would like to retrieve the ethernet address of the network interface that is
I would like to retrieve the AppSetting key from the assembly config file called:
I would like to retrieve the cpu and ram usage at that point for
I would like to retrieve data (the name in this case) from two tables
I would like to retrieve the message information from the i18n bundle (messages.properties in
I would like to retrieve a random word from a file using python, but
i would like to retrieve the element offset starting from his own x center
From Python, I would like to retrieve content from a web site via HTTPS
I would like to retrieve an error message that explains why the jvm failed

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.