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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:07:27+00:00 2026-06-03T14:07:27+00:00

I want to dynamically load a dll and construct a MyDllClass object. My code

  • 0

I want to dynamically load a dll and construct a MyDllClass object. My code is roughly as follows(unrelevant parts stripped):

MyDllClass.cs

namespace MyDllNameSpace
{
    public class MyDllClass
    {

        private EventCallBack m_DelegateCallBack = null;

        public MyDllClass(EventCallBack eventCallBack)
        {
            m_DelegateCallBack = eventCallBack;
        }

        public MyDllClass()
        {
        }
        ...
    }
}

MyDllCallBackNameSpace.cs

namespace MyDllCallBackNameSpace
{
    public delegate void EventCallBack(string message);
}

I managed to construct the object using the empty constructor but I couldn’t get other constructor working. I get ArgumentException

at System.Reflection.RuntimeConstructorInfo.InternalInvoke()  
at System.Reflection.RuntimeConstructorInfo.Invoke()  
at System.Reflection.ConstructorInfo.Invoke() at MyProgram.InitMyObject()  
at ...

Here is my code:

MyProgram.cs

public void InitMyObject(EventCallBack callBack)
    System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(DLL_PATH);
    Type type = assembly.GetType(CLASS_NAME);
    ConstructorInfo[] constructors = type.GetConstructors();
    if (type != null)
    {
        // empty constructor, works!!!
        //return constructors[1].Invoke(new object[0]); 
        // This one gives InvalidArgument exception
        return constructors[0].Invoke(new object[] {callBack});
    }
    return null;
}

MyDllCallBackNameSpace.cs file has been added to both projects(the .dll & the .exe project) and references the same physical file on my drive. But I suspect that it is still treated as different. Any ideas why it is not working, or any workarounds?

  • 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-03T14:07:29+00:00Added an answer on June 3, 2026 at 2:07 pm

    I managed to fix this buy moving MyDllCallBackNameSpace.cs into another dll. Then I referenced that dll from both projects.

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

Sidebar

Related Questions

I have a Flash in AS3. I want to dynamically load code that performs
I'm creating a CMS, and I want to dynamically load the style from the
I have a few internal Canvas xaml files which I want to load dynamically
I want to load one or more DLLs dynamically so that they run with
I want to dynamically create object of HtmlDivElement in my jsf managed bean and
I want to dynamically change content , by following code. localStorage.removeItem(some key); but current
I want to dynamically query an object with System.Linq.Dynamic . var selectData = (from
I have a bunch of links that I want to load dynamically within the
I want to dynamically load (AJAX) the text from some Microsoft Word files into
I want to dynamically load images from a database withing a PrimeFaces data table.

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.