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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:56:53+00:00 2026-05-23T12:56:53+00:00

I have a C# .dll that is envoked from within a C# application useing

  • 0

I have a C# .dll that is envoked from within a C# application useing “System.Reflection” at runtime. The .dll contains a WinForm class which is used to display information to the user. The .dll is envoked using the following code:

    DLL = Assembly.LoadFrom(strDllPath);    
    classType = DLL.GetType(String.Format("{0}.{0}", strNsCn));    
    classInst = Activator.CreateInstance(classType, paramObj);    
    Form dllWinForm = (Form)classInst;      
    dllWinForm.ShowDialog();

Now, my problem is now that I want to return a string from the WinForm .dll. This could be an error or just to show that the process completed correctly. I know how this is done when calling a method from within a requested .dll, as follows:

    System.Reflection.Assembly LoadedAssembly = System.Reflection.Assembly.Load("mscorlib.dll");
    System.Console.WriteLine(LoadedAssembly.GetName());
    object myObject = LoadedAssembly.CreateInstance("System.DateTime", false, BindingFlags.ExactBinding, null, new Object[] {2000, 1, 1, 12, 0, 0}, null, null);
    MethodInfo m = LoadedAssembly.GetType("System.DateTime").GetMethod("ToLongDateString");
    string result = (string) m.Invoke(myObject, null);

but how do you do this for my case of a WinForm called from a .dll at runtime?

Any suggestions would be most 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-05-23T12:56:54+00:00Added an answer on May 23, 2026 at 12:56 pm

    Okay, so to boil the question and the comments down, what we’re trying to do here is have a C# app that loads a dll that was implemented by a 3rd party at a later date, and the app needs to get some status information from the component in the loaded dll (the fact that the component uses WinForms vs. some other UI seems completely inconsequential).

    The best way to do it is to start out with an interface or base class that can be shared between the hosting application and the loaded component. In order to achieve this, the interface needs to be in a separate dll. So first we create a class library project and add the following class:

    using System;
    using System.Windows.Forms;
    
    namespace SimplePluginShared
    {
        public class PluginBase : Form
        {
            public virtual String GetStatus()
            {
                return null;
            }
        }
    }
    

    Then add a reference to that class library from the project that implements the component you’re loading via reflection (or share it with your third party for them to implement). Here is an example implementation of Plugin Base:

    using System;
    using System.Windows.Forms;
    using SimplePluginShared;
    
    namespace SimplePluginExample
    {
        public partial class MyForm : PluginBase
        {
            private String _status = "Unspecified";
    
            public MyForm()
            {
                InitializeComponent();
            }
    
            public override string GetStatus()
            {
                return _status;
            }
    
            private void btnGive_Click(Object sender, EventArgs e)
            {
                _status = "Give Him The Stick.";
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
    
            private void btnDontGive_Click(object sender, EventArgs e)
            {
                _status = "Don't Give Him The Stick!";
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
        }
    }
    

    And lastly the code to load and call the component:

    using System;
    using System.Linq;
    using System.Reflection;
    using System.Windows.Forms;
    using SimplePluginShared;
    
    namespace SimplePluginHost
    {
        public partial class MainForm : Form
        {
            public MainForm()
            {
                InitializeComponent();
            }
    
            private void btnBrowse_Click(Object sender, EventArgs e)
            {
                OpenFileDialog openPluginDlg = new OpenFileDialog() { DefaultExt = "dll", Multiselect = false, Title = "Open Plugin DLL", Filter = "DLLs|*.dll" };
                if (openPluginDlg.ShowDialog() == DialogResult.OK)
                {
                    txtPluginPath.Text = openPluginDlg.FileName;
                }
            }
    
            private void btnGo_Click(Object sender, EventArgs e)
            {
                Assembly pluginDll = Assembly.LoadFrom(txtPluginPath.Text);
                Type pluginType = pluginDll.GetTypes().Where(t => typeof(PluginBase).IsAssignableFrom(t)).First();
                PluginBase pluginInstance = (PluginBase)Activator.CreateInstance(pluginType);
                pluginInstance.ShowDialog();
                MessageBox.Show(pluginInstance.GetStatus());
            }
        }
    }
    

    He are some screenshots:

    Displaying the Dialog

    Displaying the Status Text

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

Sidebar

Related Questions

I have a dll that contains a templated class. Is there a way to
I have a DLL one.dll that uses a class TwoClass exported from two.dll via
I have a dll that must be useable from C etc, so I cant
I have a dll that contains a dot net assembly - common intermediate language.
I have DLL and application that will call some function in this dll. For
I have a dll that I want to read from a manually specified app.config
I have acquired a DLL that was created in Visual Basic from a third
I have a C# 4.0 Winform app that I just upgraded from 3.5 to
I have a DLL that gets loaded in my application, like so: procedure LoadTessDLL;
I have a DLL that I'm testing, which links to a DLL that has

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.