none
IMetaDataImport::FindTypeRef fails to return TypeRef token for known Type from a reference assembly RRS feed

  • Question

  • I am writing and IL re-writing profiler for .NET assemblies.

    I have the following code snippet and applying it to the EntityFramework.dll assembly function.

       

    //Enumerate all reference assemblies for current assembly				

    hResult = pMDAImport->EnumAssemblyRefs( &assemblyEnum, assemblyRefs, numElements( assemblyRefs ), &assemblyRefsCount );

    // Walk through all referenced assemblies to find System.Data.IDbCommand token

    // for( unsigned assemblyRefIdx = 0; (unmatchedTypes > 0) && (assemblyRefIdx < assemblyRefsCount); assemblyRefIdx++ ) { assemblyRef = assemblyRefs[ assemblyRefIdx ]; WCHAR tempAssName[50]; ULONG szAssNameRet = 0; hResult = pMDAImport->GetAssemblyRefProps(assemblyRef, NULL, 0, tempAssName, numElements(tempAssName), &szAssNameRet, NULL, NULL, 0, NULL); if (hResult == S_OK) { if( CLogger::isLevelEnabled( LL_Debug ) ) CLogger::Log( LL_Debug, "Searching for dependent types in assemblyRef(%08X) (%d/%d) - %S\n", assemblyRef, assemblyRefIdx + 1, assemblyRefsCount, tempAssName); } hResult = m_pMDImport->FindTypeRef( assemblyRef, L"System.Data.IDbCommand", &typeRef ); if( (m_idbCommandTypeToken == mdTokenNil) && SUCCEEDED( m_pMDImport->FindTypeRef( assemblyRef, L"System.Data.IDbCommand", &typeRef ) ) ) { m_idbCommandTypeToken = typeRef; }

    The logging confirms it sees System.data as one of the referenced assemblies which should contain the TypeRef for System.Data.IDbCommand

    014.04.22.15.33.50.951  [00002B0C]  DEBUG    Searching for dependent types in assemblyRef(23000003) (3/13) - System.Data

    Can you tell me why the FindTypeRef fails and how to get around this ?

    Regards

    Sanjay

    The hResult error is

    CLDB_E_RECORD_NOTFOUND

    0x80131130

    Record not found on lookup.


    Sanjay Mehta


    • Edited by Sanjay_HP Wednesday, April 23, 2014 12:51 AM
    Wednesday, April 23, 2014 12:50 AM

All replies

  • Hello,

    >>CLDB_E_RECORD_NOTFOUND

    This error usually shows that it's not an assembly, see it from here:

    http://blogs.msdn.com/b/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx

    Do you have a try to refer the System.Data.dll directly to check whether it will work fine?

    If it works, then I think the parameter in the current project is not suitable. You may need to check them carefully.

    If it cannot work, could you please share your whole project with us?

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 23, 2014 10:07 AM
    Moderator
  • I cannot share the project, it is too big and contains IP.
    But as you see from the snippet above the error is returned from m_pMDImport->FindTypeRef API not from ILDASM as refered in your link. The code snippet I provided should provide enough context to define the problem. Here is a summary. 1. We try to instrument a method in EntityFramework library via the JITCompilationStarted interface. 2. We try to find the typeRef for "System.Data.IDbCommand" since  some of the classes in EF implement that interface. 3. We enumerate all reference assemblies, and use the FindTypeRef API. 4. One of reference assemblies is System.data.dll which contains the definition for "System.Data.IDbCommand" but the FindTypeRef API does not return the token, instead returns hResult = 0x80131130  

    Sanjay Mehta

    Wednesday, April 23, 2014 5:01 PM
  • Hi,

    Okey, for it, I am trying to invoke someone experienced to help look into it.

    If we have any result, we will tell you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 24, 2014 8:33 AM
    Moderator
  • One more observation, The FindTypeRef API is able to find the token for "System.Data.CommandBehavior" from the same reference assembly using the same parameters. The difference I see is that one is a class definition and the other is an interface.


    Sanjay Mehta

    Thursday, April 24, 2014 3:54 PM
  • Hello,

    For this, my suggestion is to have a try to find the System.Data.IDataAdapter since it is an interface under the System.Data to see whether there may be a limit for the FindTypeRef method.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, April 25, 2014 8:35 AM
    Moderator
  • Does your code snippet work in a small standalone repro on the EF assembly? Or is it just a problem of your "big app"?

    -Karel

    Wednesday, May 14, 2014 2:13 AM
    Moderator