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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:37:11+00:00 2026-06-13T22:37:11+00:00

In my project I need to use plugins. But to use these in my

  • 0

In my project I need to use plugins. But to use these in my project I need to import an reference of the plugin. Since I can’t know how many or which plugins the project uses beforehand I would like to import them dynamically in my project.

    String path = Application.StartupPath;
    string[] pluginFiles = Directory.GetFiles(path, "*.dll");
    ipi = new IPlugin[pluginFiles.Length];
    Assembly asm;

        for (int i = 0; i < pluginFiles.Length; i++)
        {
            string args = pluginFiles[i].Substring(
                pluginFiles[i].LastIndexOf("\\") + 1,
                pluginFiles[i].IndexOf(".dll") -
                pluginFiles[i].LastIndexOf("\\") - 1);

            asm = Assembly.LoadFile(pluginFiles[i]);
            Type[] types = asm.GetTypes();

In this code example I searched all the .dll files and put them into a string list.
But how can I now load all these .dll files? Or is there a way to use these .dll files without really importing them?

  • 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-13T22:37:12+00:00Added an answer on June 13, 2026 at 10:37 pm

    Let’s assume for the sake of simplicity that all of the implementations of IPlugin have default constructors (public and no parameters).

    That said, you really want to find all types that implement this interface and create an instance of them. You’re on the right track somewhat, but you can simplify this tremendously with a little LINQ:

    String path = Application.StartupPath;
    string[] pluginFiles = Directory.GetFiles(path, "*.dll");
    
    
    ipi = (
        // From each file in the files.
        from file in pluginFiles
        // Load the assembly.
        let asm = Assembly.LoadFile(file)
        // For every type in the assembly that is visible outside of
        // the assembly.
        from type in asm.GetExportedTypes()
        // Where the type implements the interface.
        where typeof(IPlugin).IsAssignableFrom(type)
        // Create the instance.
        select (IPlugin) Activator.CreateInstance(type)
    // Materialize to an array.
    ).ToArray();
    

    That said, you might be better off using a dependency injection framework; they usually allow for dynamic loading and binding to interface implementations in assemblies not referenced at compile time.

    Also, while a bit convoluted (in my opinion), you might want to look at the System.AddIn namespaces, as they are built specifically for this purpose. However, the dependency injection route is usually much easier if you don’t have to worry about version control of contracts and the like.

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

Sidebar

Related Questions

I use maven-antrun-plugin for init config files for my project. But i need to
For my project i need to use the jQuery Rule Plugin Its looks like
In my project I need to use third party code, stored in several Git
As part of my project I need to use some Unamanged code dlls in
I am doing a project and need to use the facebook API as user
I'm starting a project where I need to use OpenJPA 2.2 and run on
I need to use python-rest-client package into my project. I tried several times for
I need to use IBM Informix for my project where I have point coordinates
I need to use some classes inside the app_code folder of a website project
For a school project i need to write or use a online programming editor.

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.