ilasm Directives and Attributes

  • Jason Bock


In this chapter, I’ll talk about the different ilasm directives and attributes that are available for the CIL developer. I’ll work from the essential directives that are needed for any valid assembly to the directives that define the custom types and their associated elements (for example, methods and fields).


Calling Convention Method Signature Instance Method Assembly Directive Code Snippet 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    To understand how the runtime actually resolves which assembly to load, check out the article entitled “How the Runtime Locates Assemblies” in the SDK.Google Scholar
  2. 2.
    I won’t discuss. os and. proces sor, as they are only used for documentation purposes in an assembly. See Section of Partition II for more information.Google Scholar
  3. 3.
    See Sections 21.10 and 22.3 of Partition II for more detailed information on how to declare custom attributes.Google Scholar
  4. 4.
    See Section 22.1.1 of Partition II.Google Scholar
  5. 6.
    Section of Partition II defines some conventions you should use, though, when employing. ver.Google Scholar
  6. 7.
    See Section 21.11 of Partition II to find a detailed explanation of why. permission isn’t used to declare security metadata.Google Scholar
  7. 8.
    For more information on security in.NET, I encourage you to read my book, NET Security (Apress, 2002).Google Scholar
  8. 9.
    See Section 21.27 of Partition II.Google Scholar
  9. 10.
    Interestingly enough, in VS.NET, VB.NET, and C#, a Windows application emits a 2 for. subsystem, but a C# class library application emits a 3, whereas a VB.NET class library application emits a 2.Google Scholar
  10. 11.
    For more information on what DLL Hell is all about, please read Steven Pratschner’s article, “Simplifying Deployment and Solving DLL Hell with the.NET Framework,” which can be found at
  11. 12.
    To be valid, though, both SimpleStruct and SimpleValueType should contain at least one member, like a field, but I haven’t covered type members yet.Google Scholar
  12. 13.
    See Section 9.7 of Partition II for more information on layouts.Google Scholar
  13. 14.
    Actually, this isn’t correct given the code here—you could compile it and it would work fine. Once you’ve read the discussion on constructors, though, come back to this example and add constructors to these types; you’ll find out that ExtendlnvisibleType won’t work anymore. The code sample has the constructor added for these types.Google Scholar
  14. 15.
    There are two other attributes you can use, specialname and rtspecialname, but they’re ignored by the runtime. See Section 9.1.6 of Partition II.Google Scholar
  15. 16.
    Although it’s out of the scope of this discussion, keep in mind that there may be issues with static fields in multithreading scenarios.Google Scholar
  16. 17.
    See Section 15.2 of Partition II for the full documentation on the field initialization syntax.Google Scholar
  17. 18.
    I won’t cover accessibility attributes again for methods, as I’ve already covered them with fields.Google Scholar
  18. 21.
    That’s how C# gets its this reference and VB.NET gets its Me reference.Google Scholar
  19. 22.
    Section 14.3 of Partition II hints that there are 10 other attributes for different calling conventions, but it doesn’t explicitly state what they are.Google Scholar
  20. 23.
    I realize you just read a discussion about instance methods and the instance reference being the first argument, so in this case you have five arguments. To avoid confusion, I won’t mention or include this implicit instance argument unless I have to clarify a specific issue.Google Scholar
  21. 24.
    See Section 13.4 of Partition II for more information on pointer types.Google Scholar
  22. 25.
    See Section 9.5.3 of Partition II for all of the gory details on type initializers.Google Scholar
  23. 26.
    Although I’ll cover VB.NET and C# compiler results in Chapter 6, I’d like to note here that the C# compiler will always add beforefieldinit if a type does not have a type initializer. If there is a type initializer, this attribute is not added.Google Scholar
  24. 27.
    See Section of Partition II.Google Scholar
  25. 28.
    It’ll also keeps your methods verifiable—see Section of Partition II for details.Google Scholar
  26. 29.
    Read Section 13.6 of Partition II for an interesting note on why you can’t derive from Sy stem. Delegate directly.Google Scholar

Copyright information

© Jason Bock 2002

Authors and Affiliations

  • Jason Bock

There are no affiliations available

Personalised recommendations