Welcome to MSDN Blogs Sign in | Join | Help

jaredpar's WebLog

Code, rants and ramblings of a programmer.

Syndication

News

Now Reading

Expert F#

What's a better book to read when learning F#?

Essential WPF

Thus far the best book I've read on WPF. Gets right down to working with WPF and the goals/history.

Purely Functional Data Structures

Reading this book makes me feel like I'm back in college. It will really get your mind going and is best read with a whiteboard handy.

Blog Roll

Eric Lippert
Dustin Campbell
Jon Skeet
Coding Horror
Brian McNamara
Brian Bondy
Hub FS
Full List

IMetaDataImport::GetParamForMethodIndex

While investigating a recent bug I found about an interesting return for GetParamForMethodIndex.  On a perfectly verifiable assembly, a call to GetParamForMethodIndex was returning a failure code. After some searching I found the return code was CLDB_E_RECORD_NOTFOUND. I was surprised at first because it's a verifiable assembly so how could the record for a parameter I knew existed not be there?

It turns out this is legal.  GetParamForMethodIndex returns a mdParamDef token by which you can query for information about a parameter with GetParamProps.  This will return the following information about a parameter. 

  • Name of the parameter
  • Attributes about the param (ByRef, Marshal, etc ...)
  • Default value

In this particular case the assembly was generated without a parameter name.  As it also had none of the information the parameter row was omitted from the metadata.  The reason is adding an empty row takes up space and provides no data. 

Note you can't reproduce this behavior with ILASM.exe.  If you omit a parameter name, ILASM.exe will add one for you and hence generate a parameter row.

Published Monday, July 30, 2007 1:09 PM by Jared Parsons

Filed under: , ,

Comments

No Comments

New Comments to this post are disabled
Page view tracker