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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:52:29+00:00 2026-05-28T00:52:29+00:00

I have a problem with reflection, basically i need to call a method of

  • 0

I have a problem with reflection, basically i need to call a method of Class like this:

public Int32 addNumer (Int32 a, Int32 b)
{
    return (a+b);
}

And i need to call it with Reflection, because i receive this input from “external” C#
software and i need to evaluate witch method i need to call.

The problem is that as Input i have 2 object passed by “prompt command line”,
o I have converted it in Byte:

Byte a = 10;
Byte b = 10;

So, when i perform Refection i see an error “cannot find method addNumber”
because the method with 2 byte in input was not found. I think that it expected
2 Int32 and not 2 Byte.

How i can resolve it?

D.

UPDATE 1:

Object result_object = target_class.InvokeMember(method, 
                           BindingFlags.InvokeMethod, null, target_object, 
                           args_values, null, null, args_names);

UPDATE 2:
i can’t CAST to Int32 because i receive this call from a EXE file:

MyProjectPrompt.exe Namespace.Class.Method param1 param2

Example:

MyProjectPrompt.exe It.Company.Math.Add 10 10

SOLUTION

ParameterInfo[] listaParametr = method_to_invoke.GetParameters();

ParameterInfo infoParam;
for(Int32 va=0;va<listaParametr.Length;va++)
{
    infoParam = listaParametr[va];

    for(Int32 va2=0;va2<args_values.Length;va2++)
    {
        if(args_names[va2]==infoParam.Name)
        {
            args_values[va2] = Convert.ChangeType(args_values[va2], 
                                                  infoParam.ParameterType);                        
        }
    }
}

Basically for EVERY Param to pass, i cast it.
After that i pass it dynamically:

Object result_object = target_class.InvokeMember(method, 
                           BindingFlags.InvokeMethod, null, target_object, 
                           args_values, null, null, args_names);
  • 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-28T00:52:29+00:00Added an answer on May 28, 2026 at 12:52 am

    Use Convert.ChangeType to change your original value to a type accepted by the method. It’ll throw an exception if no suitable conversion can be found.

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

Sidebar

Related Questions

I have a problem with reflection. I need to find the type that instantiates
I have some tricky generic type problem involving reflection. Here's the code. public @interface
i have a problem as : MyFirstClass.java public class MyFirstClass{ String strParam; MySecondClass secClass;
I have an interesting problem. I'd like to create a generic class that can
I have problem with return statment >.< I want to store all magazine names
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have a follwing class structure: public abstract class AbstractFoo { public virtual void
I have problem with this exception: Hibernate.HibernateException : Could not create the driver from
I have a problem trying to solve a situation, when I use Java Reflection

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.