Common Language Runtime Beginner Series Part 1:-CLR Basics
CLR or Common Language Runtime is a very important part of whole .net Framework and its utter importance is not seen by most of us as it works behind the scenes.This beginner series of my articles will help you to know what actually CLR is in simple terms and what are its basic features. Remember this is for beginners, or people who are not as much familiar with CLR. I will try to make this series of articles very simple so that everyone can understand and here and there i will make some simple comparisons so that the fact is understood easily.In simplifying things some facts may sound vague so please pardon me...

- In earlier days of programming there was no concept of managed code,there was only unmanaged code which means that all the things should be handled by the operating system.
- The programming languages compiled the programs written in them to the native code specific to the architecture or the CPU.
- There are many disadvantages of such an approach which we will see one by one in a series of articles.
- So first of all what is CLR....Actually speaking it can be considered as a small processing unit of its own which when given a Intermediate Language code can produce a native code to be run on that CPU.
- CLR consists of various parts in which each is a topic of research and discussion and requires an in depth analysis.
- So the process in which our programs get executed is first of all we have a code in a language it can be VB,C# or C++ now we compile this code using the respective compiler for that language.
- After this first compilation we receive a IL or Intermediate Language code, now this IL code act as input to the CLR and its Just In Time Compiler chooses the right Model to be executed for compilation for that CPU type.
- So now the JIT decides according to the CPU type and architecture which mode of compilation it should follow.
- Now after this decision JIT actually compiles and produces the native code which can be run on that CPU.
- CLR can be considered as a SandBox environment from which no code can execute outside its given bounds that is the code execution is confined and this is a major advance over the earlier model of program execution.
- So now you can say that .net can only execute the managed code and there is no need for unmanaged code but this is not true. There are some special cases where unmanaged code is the best thing till today e.g are device drivers and real time applications where performance is a bottleneck although there are algorithms which will be implemented in future CLR for support of Real Time applications.
- But .net framework also provides few ways to write unmanaged code which will not use facilities of CLR and execute in an old fashioned way.
- Both C++ and C# has ways to execute this unmanaged code.
- When the code is first compiled to an IL we get a .exe or .dll file this is what we call an assembly.
- Once you ask this assembly to be executed it is loaded into the ApplicationDomain or AppDomain of the CLR.
- AppDomain of CLR is the region in which a process is running and each assembly can get executed without creating a new process side by side with other assemblies without hampering or affecting their execution.
- Creating separate processes for execution was a performance intensive task which earlier programming languages used to do.But with CLR this performance lapse is reduced.
- The other benefit is that this code is compiled only once by the JIT and after that it can be run utilizing full power of the CPU.
- So the million dollar question is when ultimately the native code is getting generated which is also being generated by other language compilers what's the difference between this native code and the one generated by CLR.
- So the difference is that CLR places some information within this native code which tells this native code to follow the execution model and remain in bounds confined by the CLR.
- Earlier unmanaged applications never thought of maximizing the overall throughput,they always used to maximize individual applications throughput but managed code always tries to maximize the overall throughput rather then considering a single process.
So this was the first article of this Series which tells very basic things about the CLR.In future articles we will dig deep into the features provided by the CLR.
Some useful properties,classes and methods which we require mostly during development in .net
1: System.Web.HttpContext.Current.Request.ApplicationPath
System.Web.HttpContext.Current.Request.ApplicationPath gives you the applications current running path.
This list will be ever increasing as soon as i found some useful content i will publish it once again.
If you also want to share some common,useful and often ignored things in .net you can comment in there i will surely include them in the list.
Disabling IE Enhanced Security Configuration for WS2003
- Go to Add/Remove Windows Components in the Add/Remove Programs Dialogue Box and uncheck the Internet Explorer Enhanced Security Configuration
2.If uninstalling this feature also doesn't work for you then you can give this a try:- Go to HKCUSoftwareMicrosoftWindowsCurrentVersionInternet
SettingsZoneMapIEHarden if you find this entry and its value is 1 this means that IE Enhanced Security is enabled for the given user.So just play with the value and make it 0.This works in certain cases but not applicable to all just give it a try,test it and your comments are always welcome.
Dotnet and C# Begginner Series Part-1
Important Learning 1. Common Language Specification is a part of Common Type Systems which in turn is a part of Common Language Runtime. 2. We can take any language and if we can have or make a .net aware compiler for that language then we are done ie we can start writing code in that language and it will run on .net framework installed machines.We needn’t worry about the platform now, as .net will take care for that. 3. Single file assemblies and multifile assemblies.The difference is that we can have all our referenced code in a single assembly it is beneficial when we have only a small application and our client needs to download only a small part ie only that assembly and that’s done.But if we are making a big application in which there are thousands of small application so we neednot place everything into a single assembly whereas we can place things in different assemblies the benefit is that if our clients need some network related stuff so he can download that assembly and start working he needn’t download the whole application as such so it reduces the download time and make process faster. 4. What actually happens for those people who don’t know .net and are programmers in other languages is that first we write code in any .net language let’s be concerned now with only the languages which ship with .net.Now all these languages such as VB.Net ,C#,C++/CLI,J#,JScipt.net follow Common Type Specification and Common Language System.So if you write Dim myInt as Integer in vb.net and someone else write int myInt in C# it will be compiled by vbc.exe and csc.exe to same thing ie Sys.Int32 which is the example of Common Type System and thus it means they are same at the Intermidiate Language Level 5. What these compilers do is they generate Intermediate Language which is not instruction set specific ie which is not platform specific ie it does not contain any platform specific information which earlier COM assemblies ie .dll and .exe used to do. 6. One important point which comes here is that the assemblies generated by .net are different then the dll and exes generated by the COM components. 7. COM used to generate platform specific dlls or exe’s but .net generates dll’s and exe’s which contain metadata and CIL . 8. This metadata consists of manifest files which contains information about the assembly like versioning,culture information,and list of externally referenced assemblies which are required to run that assembly. 9. CIL or Common Intermidiate Language or MSIL or IL whatever you can call it is in some sense same like Java Bytecode ie they both are not platform specific. 10. ByteCode in Java contains information which Java Virtual Machine understands and then generate or run the required operating system calls and resource allocation based on operating system and the architecture.For example if I have written in my Java Code that allocate me 2MB of ram.Now the bytecode will ask the virtual machine to allocate the resource now it’s the duty of virtual machine to do the heavy lifting and make system calls or any other thing to allocate the resource. 11. So lets consider different OS only not different architectures os let say x86 architecture,and Windows platform ,now here for allocating RAM the system call could be alloc_mem(amount) so it’s the work of Virtual machine to make this call. 12. On x86 and Linux this system call might change and we could have mem_alloc(totalamount) so again it’s the work of JVM specific to x86 Linux to make that call and execute the code. 13. So a question can be why not have a single JVM which could do all this for all platforms and architecture.In theory we can have single JVM also which can first perform a check for architecture and then for the operating system and then execute in a specific way,but its not necessary because such JVM will be huge in size and too complex and slow and also as it has bigger size it would be a waste of time and network resources for the client to download that. 14. If the client doesnot need any support for Windows , Solaris,Mac,Novell and etc.. he only needs it for linux then why should he download all crap.Thus I think they have different JVM’s there might be other limitations when we come to architecture. 15. So this was the story of JVM similar thing happens here in .net also when we get CIL now when we want to run and execute this code we need a Just In Time compiler which will compile this to the platform specific information. 16. So there are two compilations going on one when the code was compiled from its base language to the IL and another compilation is when the IL code is executed. 17. This second compilation is also managed by .net framework it searches for the platform and make the required calls and allocate the required resources just like we have seen in the concept of JVM 18. For .net languages we have support of Base Class Libraries which are simply collections of pre-defined classes which we can use as starting point and then implement bigger things over them. 19. This BCL is divided into many parts grouped under various meaningful namespaces.