ICorProfiler: Why am I getting the wrong type token for the jitted function?

I have some code that is structured like this:

class A {
    void M() {}
}
delegate void B<T1,T2>(T1 key, T2 value);

      

And I am using the ICorProfiler2 API to profile this code. Now when the M method is jitted, I get the FunctionID * pointer of its ID. Then I do the following (heavily abbreviated):

mdToken functionToken = mdTypeDefNil;
mdTypeDef classToken = mdTypeDefNil;
IMetaDataImport* pMDImport = NULL;
profilerInfo->GetTokenAndMetaDataFromFunction(functionId,
        IID_IMetaDataImport, (IUnknown**) &pMDImport, &functionToken);
pMDImport->GetMethodProps(functionToken, &classToken, functionName,
        sizeof(functionName), 0, &methodAttr, &sigBlob, &sigSize, NULL,
        NULL);

      

This gives me a TypeToken in a classToken variable.

I The expected is the type in which M was declared in the source (class aka), but instead I get a delegate token of type B. So my question is, am I doing something wrong or my guess is that GetMethodProps does not correctly return the type token of type M ?

Unfortunately the GetMethodProps documentation is not very helpful: https://msdn.microsoft.com/en-us/library/ms233163(v=vs.110).aspx

Edit: To clarify: I know that the wrong type is being returned because I generated a file containing all the type / function markers and the names they map to. I checked these tokens with ILSpy : they are correct. This mapping has also been tested many times in other applications and seems to work very well, so I don't think this is the source of the problem.

+3


source to share


1 answer


Until now, no one could explain why this is happening. All my research led me to believe that the profiling API sometimes just reports the wrong method type.



Fortunately, the method tokens are unique across the entire assembly, so we now use these + assembly name to uniquely identify each method and ignore the type markers completely.

0


source







All Articles