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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:34:30+00:00 2026-06-04T02:34:30+00:00

I am using Reflection.Emit to make a exe. I have come so far that

  • 0

I am using Reflection.Emit to make a exe. I have come so far that I can create a working CIL PE. (It just output a string to Console.WriteLine.) But the argument to main method is automaticly generated (A_0).

.method public static void  Main(string[] A_0) cil managed
{
  .entrypoint
  // Code size       12 (0xc)
  .maxstack  1
  IL_0000:  nop
  IL_0001:  ldstr      "Cafe con pan"
  IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
  IL_000b:  ret
} // end of method Program::Main

contrast it with the code from a corresponding C# program

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint
  // Code size       13 (0xd)
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ldstr      "Cafe con pan"
  IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
  IL_000b:  nop
  IL_000c:  ret
} // end of method Program::Main

the argument name is args. How can I give name to the argument?
The code I use for making the method look like this:

Il = System.reflection.Emit
Re = System.Reflection
tb = Reflection.Emit.TypeBuilder

Il.MethodBuilder meth = tb.DefineMethod(
                "Main", // name
                Re.MethodAttributes.Public | Re.MethodAttributes.Static,
                // method attributes
                typeof(void),   // return type
                new Type[] { typeof(String[]) }); // parameter types

Il.ILGenerator methIL = meth.GetILGenerator();
methIL.Emit(Il.OpCodes.Nop);
methIL.Emit(Il.OpCodes.Ldstr, "Cafe con pan");
Type [] args = new Type []{typeof(string)};
Re.MethodInfo printString = typeof(Console).GetMethod("WriteLine", args);
methIL.Emit(Il.OpCodes.Call, printString);
methIL.Emit(Il.OpCodes.Ret);

I have checked the TypeBuilder.DefineMethod documentation for any clue to do that as it is the logical place to have such an info but with no avail.
Do anyone have a suggestion?

  • 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-04T02:34:32+00:00Added an answer on June 4, 2026 at 2:34 am

    Looks like MethodBuilder.DefineParameter allows you to specify parameter names:

    Sets the parameter attributes and the name of a parameter of this method, or of the return value of this method. Returns a ParameterBuilder that can be used to apply custom attributes.

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

Sidebar

Related Questions

I know you can dynamically create a .NET assembly using Emit, System.Reflection and manually
I want to create a simple application using the classes in System.Reflection.Emit. How can
I am currently working with generating dynamic types using Reflection.Emit. I have the majority
How can I generate types like these using the System.Reflection.Emit libraries: public class Test<T>
I have been looking at Reflection.Emit recently. I wrote a simple program that generates
I am using System.Reflection.Emit, and at some point I want to create a delegate
Using reflection, is it possible to create an instance of a type that inherits
I'm generating a dynamic assembly using Reflection.Emit which includes a single class. I have
There are plenty of threads on how to create a Method using Reflection.Emit but
I'm currently working on a problem that involves System.Reflection.Emit code generation. I'm trying to

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.