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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:27:08+00:00 2026-06-09T10:27:08+00:00

Basically I’m trying to call a dll by name, instantiate an object, then call

  • 0

Basically I’m trying to call a dll by name, instantiate an object, then call a method by name in that dll. I’m getting an “Exception has been thrown by the target of an invocation.” during the Method.Invoke. I’m fairly sure my problem is with the typecasting of the arguments of the method. I was wondering if anyone had any input on this exception. Additionally, any suggestions on how to revise my approach are welcome.

public void calldll(string dllName, string typeName, string methodName, string arguments) {

    string[] argumentArray = arguments.Split(new char[] { '|' }, StringSplitOptions.None);

    Assembly assembly = Assembly.LoadFrom(dllName);
    System.Type type = assembly.GetType(typeName);
    Object o = Activator.CreateInstance(type);
    MethodInfo method = type.GetMethod(methodName);
    ParameterInfo[] parameters = method.GetParameters();

    object[] methodParameters = new object[parameters.GetLength(0)];

    for (int i = 0; i < parameters.Length - 1; i++)
    {
        var converter = TypeDescriptor.GetConverter(parameters[i].GetType());
        methodParameters[i] = converter.ConvertFrom(argumentArray[i]);
    }

    method.Invoke(o, methodParameters); }
  • 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-09T10:27:09+00:00Added an answer on June 9, 2026 at 10:27 am

    I found two issues with your code:

    1. You are not looping over all parameters. You should remove -1 from the for loop.
    2. When you are creating your converter, you call the GetType() method. This returns the Type of the ParameterInfo object, not the Type of the parameter. Use the property ParameterType instead.

    All in all, change the first lines in the for loop to this:

    for (int i = 0; i < parameters.Length; i++)
    {
       var converter = TypeDescriptor.GetConverter(parameters[i].ParameterType);
    

    Once you have done these corrections, I believe your code should run as intended. At least it did for me when I tested a simple void Hello(int x, string y) method.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically I want to check the extended permissions the user has granted my app.
Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.
Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically, I have a main page (parent page) with a link that opens up

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.