adrianstone55 / SymbolSort

A Utility for Measuring C++ Code Bloat
http://gameangst.com/?p=320
Apache License 2.0
117 stars 17 forks source link

BadImageFormatException on x64 #29

Open pranavsharma opened 5 years ago

pranavsharma commented 5 years ago

Compiled with VS2017 15.9.3 Enterprise edition using x64/AnyCPU. Registered "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\DIA SDK\bin\amd64\msdia140.dll". When I run the exe, it throws an error:

PS C:\Users\foobar\work_projects\SymbolSort> C:\Users\foobar\work_projects\SymbolSort\bin\Release\SymbolSort.exe -in C:\Users\foobar\work_projects\someproduct\build\Windows\RelWithDebInfo\RelWithDebInfo\someproduct.pdb -out symbol_sort.txt

Loading symbols from C:\Users\foobar\work_projects\someproduct\build\Windows\RelWithDebInfo\RelWithDebInfo\someproduct.pdb

Unhandled Exception: System.BadImageFormatException: Retrieving the COM class factory for component with CLSID {761D3BCD-1304-41D5-94E8-EAC54E4AC172} failed due to the following error: 800700c1  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).
   at SymbolSort.SymbolSort.ReadSymbolsFromPDB(List`1 symbolsOutput, String filename, String searchPath, UserFlags options) in C:\Users\foobar\work_projects\SymbolSort\SymbolSort.cs:line 1181
   at SymbolSort.SymbolSort.LoadSymbols(InputFile inputFile, List`1 symbols, String searchPath, UserFlags options) in C:\Users\foobar\work_projects\SymbolSort\SymbolSort.cs:line 1550
   at SymbolSort.SymbolSort.Main(String[] args) in C:\Users\foobar\work_projects\SymbolSort\SymbolSort.cs:line 0
skottmckay commented 4 years ago

Did you add a reference to the dll?

In order to get the msdia140 interop to work you must add msdia140.dll as a reference to the C# project. That is done either by dragging and dropping the dll onto the references folder in the C# project or by right clicking the references folder, selecting "Add Reference" and then browsing for the msdia140 dll.

That fixed this error for me but led to another one:

Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {E6756135-1E65-4D17-8576-610761398C3C} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

You also need to register the non-platform specific msdia140.dll in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\DIA SDK\bin\msdia140.dll" to fix that.