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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:42:17+00:00 2026-05-31T17:42:17+00:00

In the newest version of the .NET framework, version 4.5, the MethodBuilder class has

  • 0

In the newest version of the .NET framework, version 4.5, the MethodBuilder class has a method called SetMethodBody that I believe is exactly what I’m looking at as an alternative to using ILGenerator (which is annoying and limited in odd ways). The documentation can be found here, although since .NET 4.5 is not out yet, it is not fully documented. I can supply all but two of the arguments, but the rest I will need help with.

The first that I don’t understand is byte[] localSignature, the third argument. MSDN states that it is “An array of bytes that contain the serialized local variable structure. Specify null if the method has no local variables.” The trouble is, that’s all it says, and I can’t find out the format of a “serialized local variable signature.” I have tried looking in the ECMA-335 spec, but all I have found is how to specify the local variables in unassembled CIL. If anybody could help me figure this out, it would be much appreciated.

Also, the last argument is IEnumerable<int> tokenFixups, which is “A collection of values that represent offsets in il, each of which specifies the beginning of a token that may be modified. Specify null if the method has no tokens that have to be modified.”. I suspect that I won’t need to use these, but I’d like to know what they are anyway.

Thanks,
Brandon

  • 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-31T17:42:18+00:00Added an answer on May 31, 2026 at 5:42 pm

    The real answer to my question was posted as a comment, instead of an answer, so in case anybody else ever has this question… here’s the posted answer:

    You’ll need the SignatureHelper class. Fixups are only for compilers that translate native code to IL, like C++/CLI. – Hans Passant Mar 10 at 13:02

    So… in order to get the byte array for the local signatures, you can execute this code:

    var sig = SignatureHelper.GetLocalVarSigHelper(this.module);
    sig.AddArgument(typeof(int)); //Local #0 is of type int
    ...
    sig.AddArgument(typeof(string)); //Local #n is of type string
    var sigArray = sig.GetSignature();
    

    And in order to set the method body on the MethodBuilder, you call

    MethodBuilder.SetMethodBody(il, maxStack, sigArray, handlers, fixups);
    

    …where il is a byte[] with valid IL instructions (see this page), maxStack is an integer with the number of spots to reserve on the stack for the method, handlers is an System.Reflection.Emit.ExceptionHandler[], and fixups is a int[] array that can be ignored (with one exception, see below.)

    One thing that I disagree with in Hans Passant’s comment is that fixups are not only for compilers that translate native code into IL. I discovered when working on this that if you try to emit a call to a MethodBuilder method, it emits the wrong instruction. Looking at ILGenerator in .NET reflector, I found out that they emit a fixup each time they emit a method call. Adding a fixup for each method call indeed fixed this problem. There may be other places where you need to emit a fixup for it to work correctly, but I haven’t looked into it much.

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

Sidebar

Related Questions

I'm using Blowfish.NET newest version,but there is one problem. responce = new byte[6] {
When I am working in .NET 2.0 projects with the newest version of ReSharper
Anybody has any idea why this snippet is NOT working in newest version of
I'd like to version a grails domain class by DateTime such that: each primary
I'm using some third-party controls that use an older version of the ASP.NET Ajax
the previous version of the app has some implicit with the newest version, and
When I try to compile the newest version of Clisp on Ubuntu 8.04 I
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I'm trying to port an application to the newest version of Mozilla Prism (1.0b1
The newest App Engine SDK (1.2.1) has an API call to compute an ID

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.