1

What is the MSIL, CLR, What is the CTS means there are n number of websites that explaining about those concepts and we all know that, but If we want to learn the exact end to end process of source code to machine code conversion process with workflow image, no one explained everything in one place.

So My question here is different from others that we can get the details like Source code to MSIL (Assembly) and then it will be converted to Native code by using the jit compiler etc but when we compile, there is no clear picture of what happening behind the scene and what is the sequence order between Assembly(.dll or.exe) ILASM.exe, MSIL, CLR, CLS, CTS and all. When these things will be called?.

Could anyone explain the overview of the Dot Net framework source code compilation process step by step and end to end with a sample picture? And I am sure that it will be helpful for all others too who looking total .net compilation process in one place.

8
  • The following webpage is a good reference : developerin.net/a/39-Intro-to-.Net-FrameWork/… Source code (.cs and .vb) modules are first compiled into obj files (intermediate MSIL). Then the obj files are linked together into an executable. Commented Apr 15, 2019 at 11:28
  • 1
    It's an interesting research area, but the question here is still just asking for reference material that is definitely already available online. Not sure if on topic for SO. Commented Apr 15, 2019 at 11:49
  • 1
    Check this: github.com/dotnet/roslyn/wiki/Roslyn-Overview Commented Apr 15, 2019 at 11:57
  • @Jdweng I already mentioned, we will get lots of websites, but clear picture & explanations are not there. I will ask my question, let me know the answer. CLS & CTS called or executed before MSIL or after? Commented Apr 15, 2019 at 12:02
  • @Nyerguds, Yes materials are available, but that's not in the same page, we have to search one by one because in all pages they explained just an overall process but not explained each step and when it will be called or processed like that. Commented Apr 15, 2019 at 12:09

1 Answer 1

1

Explaining this is way better using a whiteboard and lots of time but I will give it a try.

.NET Compile/Build => Convert C#/VB.NET code into PE exe format with MSIL in it + some trickery to load the .NET framework(CLR).

Windows only recognizes PE format executables. But it cannot run MSIL as is. So a .NET exe is bootstrapped with .NET framework assemblies (for JIT compilation, GC etc) as part of the compile/build process. This is a kind of a trick to fool the Windows OS. The OS launches it as a normal process but the control is not handed over to your MSIL code directly. Instead it is handed over to .NET CLR assemblies (which are normal machine code dlls). The .NET CLR assemblies then start JIT compiling your MSIL code packaged in the exe and take over memory and thread management.

This is the missing piece which most novice .NET developers get confused with. So the simple trick is; a .NET exe has extra bootstrapping code that gets executed before your MSIL is reached. All the remaining stuff like ASP.NET, WPF is just those CLR dlls that get loaded. And this is why a .NET exe is way slower than a native C/C++ exe.

Your other queries

ILASM -> is a tool that can read .NET exe files and display the MSIL it contains. Tools like Reflector can even convert this MSIL code back into C#/VB.NET

CLR -> are those assemblies that are bootstrapped as part of the compile process and loaded in memory as needed. Its what is running your MSIL code.

CTS -> is just the type system against which you write your code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.