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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:17:49+00:00 2026-05-10T17:17:49+00:00

What I have now (which successfully loads the plug-in) is this: Assembly myDLL =

  • 0

What I have now (which successfully loads the plug-in) is this:

Assembly myDLL = Assembly.LoadFrom('my.dll'); IMyClass myPluginObject = myDLL.CreateInstance('MyCorp.IMyClass') as IMyClass; 

This only works for a class that has a constructor with no arguments. How do I pass in an argument to a constructor?

  • 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. 2026-05-10T17:17:50+00:00Added an answer on May 10, 2026 at 5:17 pm

    You cannot. Instead use Activator.CreateInstance as shown in the example below (note that the Client namespace is in one DLL and the Host in another. Both must be found in the same directory for code to work.)

    However, if you want to create a truly pluggable interface, I suggest you use an Initialize method that take the given parameters in your interface, instead of relying on constructors. That way you can just demand that the plugin class implement your interface, instead of ‘hoping’ that it accepts the accepted parameters in the constructor.

    using System; using Host;  namespace Client {     public class MyClass : IMyInterface     {         public int _id;         public string _name;          public MyClass(int id,             string name)         {             _id = id;             _name = name;         }          public string GetOutput()         {             return String.Format('{0} - {1}', _id, _name);         }     } }   namespace Host {     public interface IMyInterface     {         string GetOutput();     } }   using System; using System.Reflection;  namespace Host {     internal class Program     {         private static void Main()         {             //These two would be read in some configuration             const string dllName = 'Client.dll';             const string className = 'Client.MyClass';              try             {                 Assembly pluginAssembly = Assembly.LoadFrom(dllName);                 Type classType = pluginAssembly.GetType(className);                  var plugin = (IMyInterface) Activator.CreateInstance(classType,                                                                      42, 'Adams');                  if (plugin == null)                     throw new ApplicationException('Plugin not correctly configured');                  Console.WriteLine(plugin.GetOutput());             }             catch (Exception e)             {                 Console.Error.WriteLine(e.ToString());             }         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a view page(request) which loads page.html. Now after successfully loading
Right now I have this SQL query which is valid but always times out:
I inherited this project which used to build & run successfully (years ago...). Now
We have a script right now which our Windows users run on a Linux
I have a datetime called dispatched_time which I am subtracting from Time.now which results
I now have a running Java program which only lacks of the final step,that
I have an application which now is on google play. Ther developement and testing
I have a cluster of 500 linux boxes which now need to use the
I have an MVC3/EF4.1 app that I'm building which now works fine on my
I have a PHP-script originally developed on Ubuntu, which now has to run on

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.