1

I am trying to inspect a .pdb using the DIA SDK from C# but I cannot get the user defined types using this code:

string pdbFileName = @"c:\test.pdb";
var sourceClass = new DiaSourceClass();
sourceClass.loadDataFromPdb(pdbFileName);
IDiaSession session;
sourceClass.openSession(out session);    

IDiaEnumSymbols symbols;
session.globalScope.findChildren(SymTagEnum.SymTagUDT, null, 0, out symbols);

I get different results if I reference dia2.tlb or dia2.dll from my C# project.

If I reference dia2.tlb, the function call completes successfully, but I get no symbols back. This is the same if I pass SymTagEnum.SymTagPublicSymbol to findChildren too.

If I reference dia2.dll, the function throws a NotImplementedException instead. In this case, passing SymTagPublicSymbol to findChildren does return symbols.

Has anyone encountered this? I think referencing the .dll is correct, but I do not know why I get the NotImplementedException thrown.

IDL/DLL

I created the dia2.tlb and dia2.dll using the commands in a VS command prompt:

cd C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional

midl /I "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\DIA SDK\idl";"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\DIA SDK\include" dia2.idl /tlb dia2.tlb

tlbimp dia2.tlb

Many thanks.

Jay8ee
  • 101
  • 1
  • 8
  • DIA has high DLL Hell risks, every VS version has another one. Got a lot worse in VS2017 since it no longer registers its components in the registry. So non-zero odds that you actually loaded an old version of the COM component. You can enable unmanaged debugging and use Debug > Windows > Modules to see that. [Check this](https://stackoverflow.com/a/45312032/17034), note the regsvr32 step. And verify the flavor of PDB you generate, it can't be the newer "Portable" format. – Hans Passant Dec 04 '18 at 12:26
  • Thanks @HansPassant I enabled native debugging and checked the modules, it was loading an old version so I used `regsvr32`. Debugging again I see it is now using the new module. However I am still getting the `NotImplementedException`. – Jay8ee Dec 04 '18 at 13:02
  • Hmm, now what. The only other things I can see wrong are "dia2.dll", the filename is msdia140.dll. And always favor using the interface over the fake class, so `new DiaSource()`. Also required to embed the interop types, a setting you always prefer. – Hans Passant Dec 04 '18 at 13:37
  • `dia2.dll` is the dll that is generated from the `midl` and `tlbimp` steps. Referencing that DLL causes the application to go on and load `msdia140.dll` underneath. – Jay8ee Dec 04 '18 at 13:39

0 Answers0