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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:19:14+00:00 2026-05-31T05:19:14+00:00

I have a method as shown below… public bool MakeRequest(string[] args) { try {

  • 0

I have a method as shown below…

public bool MakeRequest(string[] args)
    {
        try
        {
            sXmlRequest = args[0];
            sResponse = "";
            Console.WriteLine(sXmlRequest);
            sw.Write(sXmlRequest);
            sw.Flush();
            sResponse = sr.ReadToEnd();
            return true;
        }
        catch (Exception e)
        {
            sResponse = e.Message;
            return false;
        }

    }

I have to call this method using Reflection, because of the way the entire framework is setup.

Here is the code I’m using to call it

string[] innerargs = {"Dummy Args"};
string pAssembly = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\TCPConnector.dll";
Assembly assemblyInstance = Assembly.LoadFrom(pAssembly);
Type tConnector = assemblyInstance.GetType("Fit.TcpConnector");
Object oLateBound = assemblyInstance.CreateInstance(tConnector.FullName);

result = tConnector.InvokeMember("MakeRequest", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, oLateBound, innerargs);

This is returning me MissingMethodException saying the method Fit.TcpConnector.MakeRequest is not found.

However, if I change the signature of the MakeRequest to

  public bool MakeRequest(string args)

instead of

  public bool MakeRequest(string[] args)

then, it is working. Can anybody point me in right direction in calling the function which takes array as its parameter?

  • 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-31T05:19:14+00:00Added an answer on May 31, 2026 at 5:19 am

    You have to pass it an array that contains your array:

    tConnector.InvokeMember(
        "MakeRequest",
        BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
        null, oLateBound, new object[] { innerargs });
    

    That’s because each item in the array you pass to the method represents one parameter to the function. And since you function has one parameter of type string[], you need to give it an array that contains one item of type string[].

    That being said, I think using GetMethod() and Invoke() is clearer than InvokeMember():

    var makeRequestMethod = tConnector.GetMethod("MakeRequest");
    makeRequestMethod.Invoke(oLateBound, new object[] { innerargs });
    

    Your incorrect code compiles because of array covariance as Eric Lippert pointed out in his answer.

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

Sidebar

Related Questions

I have created a Method shown below, public BOEod CheckCommandStatus(BOEod pBo, IList<string> pProperties) {
I have a method which uses CyclicBarrier as shown below: public void getMessage(Message obj){
I have one of my class method like this shown below : public function
I have made my custom In extension method as shown below: public static class
I have a method (shown below) that I discovered can be reused in code
I have re-factored one of the method as shown below ,personally I think it
Case 1 I have 2 synchronized methods as shown below: class A { public
I have a create method as shown below, in which I want to (if
I have a public following sub in my code as shown below: Public Sub
I have the method shown below which is generating a CA1822 Code Analysis warning.

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.