pune
pune

Reputation: 99

How to run ildasm on .Net core exe/assembly?

I'm trying to run ildasm (Intermediate Language Disassembler) installed as part of Visual Studio 2019 against .NetCore3.1 console app.

Use Developer command prompt of Visual Studio 2019 and run following command

ildasm.exe D:\DotNet\IntroductionToCsharp\IntroductionToCsharp\bin\Debug\netcoreapp3.1\IntroductionToCsharp\bin\Debug\netcoreapp3.1\IntroductionToCsharp.exe

But following error occur:

'D:\DotNet\IntroductionToCsharp\IntroductionToCsharp\bin\Debug\netcoreapp3.1\ IntroductionToCsharp.exe' has no valid CLR header and cannot be disassembled

this folder content

Note: running the same command on non-Core (.Net Framework 4.x) exe works fine. Maybe there is something special needed to look at IL in .Net Core?

Upvotes: 5

Views: 5192

Answers (2)

Mihai Albert
Mihai Albert

Reputation: 1513

As it was pointed out already, the .exe in .NET Core is nothing more than a host. It's sole purpose is to get the CoreCLR loaded then JIT compile and execute your assembly's Main method. The code itself is stored within the .dll. You can check this with your favorite disassembler (ILDASM, JetBrains' dotPeek, ILSpy, etc).

Why could an IL disassembler work against an .exe in .NET Framework ? Because the executable would be a managed assembly, with a corresponding managed header. Unlike .NET Core, .NET Framework has extensive support from the Windows operating system's Image Loader to get everything set up and then run the managed code within the executable. See the second point discussed here.

Upvotes: 6

HLourenco
HLourenco

Reputation: 388

NOTE: EXE in netcore exist just for "windows users", you should use always dll

See here

You can try this steps for netcore assembly (dll):

1 You need to have coreclr in the same folder of you dll netcore

2 (run commands in commandline VS)

ildasm.exe /all /out:<path to output>.il <path to dll>.dll

Upvotes: 2

Related Questions