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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:15:06+00:00 2026-05-28T02:15:06+00:00

How can I pass a parameter as a reference with MethodInfo.Invoke ? This is

  • 0

How can I pass a parameter as a reference with MethodInfo.Invoke?

This is the method I want to call:

private static bool test(string str, out byte[] byt)

I tried this but I failed:

byte[] rawAsm = new byte[]{};
MethodInfo _lf = asm.GetType().GetMethod("test", BindingFlags.Static |  BindingFlags.NonPublic);
bool b = (bool)_lf.Invoke(null, new object[]
{
    "test",
    rawAsm
});

The bytes returned are null.

  • 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-28T02:15:07+00:00Added an answer on May 28, 2026 at 2:15 am

    You need to create the argument array first, and keep a reference to it. The out parameter value will then be stored in the array. So you can use:

    object[] arguments = new object[] { "test", null };
    MethodInfo method = ...;
    bool b = (bool) method.Invoke(null, arguments);
    byte[] rawAsm = (byte[]) arguments[1];
    

    Note how you don’t need to provide the value for the second argument, because it’s an out parameter – the value will be set by the method. If it were a ref parameter (instead of out) then the initial value would be used – but the value in the array could still be replaced by the method.

    Short but complete sample:

    using System;
    using System.Reflection;
    
    class Test
    {
        static void Main()
        {
            object[] arguments = new object[1];
            MethodInfo method = typeof(Test).GetMethod("SampleMethod");
            method.Invoke(null, arguments);
            Console.WriteLine(arguments[0]); // Prints Hello
        }
    
        public static void SampleMethod(out string text)
        {
            text = "Hello";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I can pass a string as the second parameter to the
if i have a protected method, can i pass in a parameter where the
I want to pass ;;; string as a string parameter in my Ant task:
How can i pass enum parameter by reference in java? Any solution?
I see that with SQL Server 2005 you can pass a parameter as numeric
When I submit a form in HTML, I can pass a parameter multiple times,
How can I pass the Parameter to a function. for example public void GridViewColumns(params
name_iexact keyword is a parameter we can pass to filter function in django.model. Can
Simple task like make AJAX request , pass one parameter and return result, can
How can I pass parameters in an OLE DB Source to call a table-valued

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.