Problems with IMetaDataImport::ResolveTypeRef Method

☆樱花仙子☆ 提交于 2019-12-04 10:42:58
Paulie

Uff, I finally get rid of this ... The solution is not call ResolveTypeRef, but create your own method to resolve type:

  mdToken ptkResScope;
  uint len;
  metadataImport.GetTypeRefProps(typeRef, out ptkResScope, null, 0, out len);
  StringBuilder sb = new StringBuilder((int)len);
  metadataImport.GetTypeRefProps(typeRef, out ptkResScope, sb, len, out len);
  string className = sb.ToString();
  foreach (loadedModule ) {   // this is quite tricky part ...     
    metadataImportForLoadedModule = GetMetaDataImportForModule(loadedModule);
    metadataImportForLoadedModule.FindTypeDefByName(className, mdToken.Nil, out typeDef);
    if ( typeDef.IsNonNil(CorTokenType.mdtTypeDef) ) {
      return typeDef;
      }
    }

The idea comes from David Broman's CLR Profiling API Blog: Metadata Tokens, Run-Time IDs, and Type Loading (really good reading if you are interested in MetaDataImport).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!