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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:34:02+00:00 2026-05-17T22:34:02+00:00

I’m generating dynamic types using ILGenerator.Emit. I am generating a method body that will

  • 0

I’m generating dynamic types using ILGenerator.Emit. I am generating a method body that will store the types of the method arguments in an array. To actually store the elements in the array I am looping through parameters of a given method and building up the necessary IL to store the elements. On the second iteration a Break instruction appears after the Stelem.ref (L_003d below) instruction. This always happens on the second iteration and I cannot figure out why. Here is the code:

        ilGenerator.Emit(OpCodes.Ldc_I4, exampleMethod.GetParameters().Length);
        ilGenerator.Emit(OpCodes.Newarr, typeof(Type));
        ilGenerator.Emit(OpCodes.Stloc, typeArray);

        for (int idx = 0; idx < exampleMethod.GetParameters().Length; idx++)
        {
            ilGenerator.Emit(OpCodes.Ldloc, typeArray);
            ilGenerator.Emit(OpCodes.Ldc_I4, idx);
            ilGenerator.Emit(OpCodes.Ldarg, idx + 1);
            ilGenerator.Emit(OpCodes.Box, typeof(int));
            ilGenerator.EmitCall(OpCodes.Callvirt, typeof(object).GetMethod("GetType"), null);
            ilGenerator.Emit(OpCodes.Stelem_Ref, idx);//second iteration causes a break to be output in the IL
        }

        ilGenerator.Emit(OpCodes.Ret);

and the IL output is here

.method public virtual instance int32 Add3(int32, int32, int32) cil managed
 {
.maxstack 3
.locals init (
    [0] class [mscorlib]System.Type[] typeArray)
L_0000: ldc.i4 3
L_0005: newarr [mscorlib]System.Type
L_000a: stloc.0 
L_000b: ldloc.0 
L_000c: ldc.i4 0
L_0011: ldarg A_0
L_0015: nop 
L_0016: nop 
L_0017: box int32
L_001c: callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
L_0021: stelem.ref 
L_0022: nop 
L_0023: nop 
L_0024: nop 
L_0025: nop 
L_0026: ldloc.0 
L_0027: ldc.i4 1
L_002c: ldarg A_1
L_0030: nop 
L_0031: nop 
L_0032: box int32
L_0037: callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
L_003c: stelem.ref 
**L_003d: break** 
L_003e: nop 
L_003f: nop 
L_0040: nop 
L_0041: ldloc.0 
L_0042: ldc.i4 2
L_0047: ldarg A_2
L_004b: nop 
L_004c: nop 
L_004d: box int32
L_0052: callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
L_0057: stelem.ref 
L_0058: ldarg.0 
L_0059: nop 
L_005a: nop 
L_005b: nop 
L_005c: ret 
}

Any pointers or suggestions would be greatly appreciated.

Many thanks

Dermot

  • 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-17T22:34:03+00:00Added an answer on May 17, 2026 at 10:34 pm

    The opcode for break is 0x01, which incidentally is also the idx value you pass as a parameter to the stelem.ref emit. Note that there’s an extra ldarg.0 on the third iteration (where idx is 2).

    You should not specify a parameter to the stelem emit.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.