Basic .NET Framework

1. What is an IL?

A. MSIL stands for Microsoft Intermediate Language in short MSIL or IL(Intermediate Language). When you compile a program the CLR will compile the code into MSIL code. Which will then be included in the assembly[exe/dll]. When you run the program in client place. The clr will manage to convert the MSIL into machine language by a process called Jitting.

When we compile our .Net Program using any .Net compliant language like (C#, VB.NET, C++.NET) it does not get converted into the executable binary code but to an intermediate code, called MSIL or IL in short, understandable by CLR. MSIL is an OS and H/w independent code. When the program needs to be executed, this MSIL or intermediate code is converted to binary executable code, called native code. The presence of IL makes it possible the Cross Language Relationship as all the .Net compliant languages produce the similar standard IL code.

2. What is a CLR?

A. CLR Stands For common language runtime. It is the implementation for CLI Common language implementation. The core run time engine in the Microsoft .Net framework for executing .net applications. The CLR Supplies Managed code with services such as cross language integration, code access security object life time management, resource management, type safety, pre-emptive threading, metadata services(type reflections) and debugging and profiling support.

The most important part of the .NET Framework is the .Net Common Language Runtime (CLR) also called .Net Runtime in short. It is a framework layer that resides above the Operating System and handles/manages the execution of the .NET applications. Our .Net programs don't directly communicate with the Operating System but through CLR.

3. What is CTS?

A. CTS stand for Common Type System.
The CTS makes available a common set of data types so that compiled code of one language could easily interoperate with compiled code of another language by understanding each others’ data types.

A fundamental part of the .NET Framework's Common Language Runtime (CLR), the CTS specifies no particular syntax or keywords, but instead defines a common set of types that can be used with many

different language syntaxes.

4. What is a CLS (Common Language Specification)?

A. Common Language Specification (CLS):The Common Language Specification (CLS) describes a set of features that different languages have in common.

The CLS includes a subset of the Common Type System (CTS).

5. What is a Managed Code?

A. By managed code, it means that the complete life cycle and execution is managed by the .NET

(CLR). The .NET CLR manages the memory on behalf of the managed code, performs garbage collection on the managed heap, perform assembly validation and assembly (component) resolution on behalf of the program. The CLR also maintains the security constraints applied to the managed code

Managed code is code that is written to target the services of the Common Language Runtime. In order to target these services, the code must provide a minimum level of information (metadata) to the runtime. All C#, Visual Basic .NET, and JScript .NET code is managed by default. Visual Studio .NET C++ code is not managed by default, but the compiler can produce managed code by specifying a command-line switch (/CLR).

6. What is a Assembly?

A. The .NET assembly is the standard for components developed with the Microsoft.NET. Dot NET assemblies may or may not be executable, i.e., they might exist as the executable (.exe) file or dynamic link library (DLL) file. All the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest. The designers of .NET have worked a lot on the component (assembly) resolution.

7. What are the different types of Assembly?

There are three kinds of assemblies in .NET;

Private Assemblies.

Shared Assemblies.

Satellite Assemblies.

Private assemblies are simple and copied with each calling assemblies in the calling assemblies folder.

Shared assemblies (also called strong named assemblies) are copied to a single location (usually the Global assembly cache). For all calling assemblies within the same application, the same copy of the shared assembly is used from its original location. Hence, shared assemblies are not copied in the private folders of each calling assembly. Each shared assembly has a four part name including its face name, version, public key token and culture information. The public key token and version information makes it almost impossible for two different assemblies with the same name or for two similar assemblies with different version to mix with each other.

An assembly can be a single file or it may consist of the multiple files. In case of multi-file, there is one master module containing the manifest while other assemblies exist as non-manifest modules. A module in .NET is a sub part of a multi-file .NET assembly. Assembly is one of the most interesting and extremely useful areas of .NET architecture along with reflections and attributes, but unfortunately very few people take interest in learning such theoretical looking topics.

Satellite Assembly Satellite assemblies are often used to deploy language-specific resources for an application. These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language. When uninstalling, the application removes only the satellite assemblies associated witha given language and .NET Framework version. No core .NET Framework files are removed

unless the last language for that .NET Framework version is being removed. For example, English and Japanese editions of the .NET Framework version 1.1 share the same core files.

The Japanese .NET Framework version 1.1 adds satellite assemblies withlocalized resources in a \ja subdirectory. An application that supports the .NET Framework version 1.1,

regardless of its language, always uses the same core runtime files

A8. What is NameSpace?

A. A namespace is a logical naming scheme for types in which a simple type name, such as MyType, is preceded with a dot-separated hierarchical name. Such a naming scheme is completely under control of the developer. For example, types MyCompany.FileAccess.A and MyCompany.FileAccess.B might be logically expected to have functionally related to file access. The .NET Framework uses a hierarchical naming scheme for grouping types into logical categories of related functionality, such as the ASP.NET application framework, or remoting functionality. Design tools can make use of namespaces to make it easier for developers to browse and reference types in their code.

9. What is Difference between NameSpace and Assembly?

A. A namespace is a logical naming scheme for types in which a simple type name, such as MyType, is preceded with a dot-separated hierarchical name. Such a naming scheme is completely under control of the developer. For example, types MyCompany.FileAccess.A and MyCompany.FileAccess.B might be logically expected to have functionally related to file access. The .NET Framework uses a hierarchical naming scheme for grouping types into logical categories of related functionality, such as the ASP.NET application framework, or remoting functionality. Design tools can make use of namespaces to make it easier for developers to browse and reference types in their code.
The concept of a namespace is not related to that of an assembly. A single assembly may contain types whose hierarchical names have different namespace roots, and a logical namespace root may span multiple assemblies. In the .NET Framework, a namespace is a logical design-time naming convenience, whereas an assembly establishes the name scope for types at run time.

10. If you want to view an Assembly how do you go about it?

A. There Is No other tool to view or to get about assembly other than ILDASM.

11. What is Manifest?

A. Every assembly, whether static or dynamic, contains a collection of data that describes how the elements in the assembly relate to each other. The assembly manifest contains this assembly metadata. An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes. The assembly manifest can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE file that contains only assembly manifest information.

12. Where is version information stored of an assembly?

A. Assembly version information is stored in Manifest.

13. Is versioning applicable to private assemblies?

A. No.

14. What is GAC?

A. The Global Assembly Cache or the popular acronym GAC refers to the machine-wide code cache in any of the computers that have been installed with common language runtime. The GAC or the Global Assembly Cache in .NET Framework acts as the central place for registering assemblies.

15. what is the concept of strong names?

A. Strong name is basically linked with shared Assemblies. When you publish your assembly in Globle Assembly Cache at that time you need to give strong name to that assembly. To give strong name you can use sn.exe from .net command prompt.
A strong name consists of the assembly's identity — its simple text name, version number, and culture information (if provided) — plus a public key and a digital signature. It is generated from an assembly file using the corresponding private key. (The assembly file contains the assembly manifest, which contains the names and hashes of all the files that make up the assembly.)
Remember that once you give an assembly a strong name, all assemblies that reference that assembly also have to have strong names, so that the security of the strongly named assembly is not compromised.
Note Once an assembly is created, you cannot sign it with a strong name. You can sign an assembly with a strong name only when you create it.

16. How to add and remove an assembly from GAC?

A. Each computer that .NET is installed on has a Global Assembly Cache (GAC) located in the Assembly folder in theWindows directory (usually: C:\WinNT\Assembly). The GAC contains information about shared assemblies which are components that can be shared among several applications (Ex. a DLL). Shared assemblies must have globally unique names derived from their strong names (public keys generated to distinguish assemblies from other assemblies that may have the same names) which is Microsoft's solution to DLL hell. The GAC, not the registry, is the store for this information. When an application loads the GAC is examined by the Common Language Runtime to determine if the version of a shared component exists that is compatible with the one referenced by the application.

The gacutil.exe that ships with .NET can be used to add or remove a shared assembly from the GAC.

To add a shared assembly, from the command line enter:

gacutil.exe /i myassembly.dll

To remove a shared assembly, from the command line enter:

gacutil.exe /u myassembly.dll

When viewing the GAC in Windows Explorer shfusion.dll is used to provide the user interface. You can locate and rename this DLL to view the GAC like any other folder.

17. What is Delay signing?

A. Delay signing allows to place a shared assembly in the GAC

by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and

the component or assembly is ready to be deployed.

This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at

different stages of development.

18. What is garbage collection?

A. The garbage collector in .Net takes care of bulk of the memory management responsibility, freeing up the developer to focus on core issues. The garbage collector is optimized to perform the memory free-up at the best time based upon the allocations being made. Java developers have enjoyed the benefits of Garbage collection. VB developers are also used to a certain amount of flexibility in these terms and .Net provides full-fledged memory management capabilities for managed resources.

19. Can we force garbage collector to run?

A. Yes we can force garbage collection by invoking the (GC.Collect) method from the program. This is not advisable and should be used only in extreme cases.

20. What is reflection?

A. Refelction is the mechanism of discovering class information solely at run time.

Reflection is the ability to read metadata at runtime. Using reflection, it is possible to uncover the methods, properties, and events of a type, and to invoke them dynamically. Reflection also allows us to create new types at runtime, but in the upcoming example we will be reading and invoking only.

21. What are different types of JIT?

Pre-JIT (Compiles entire code into native code at one stretch)

Ecno-JIT (Compiles code part by part freeing when required)

Normal JIT (Compiles only that part of code when called and places in cache)

22. What are Value types and Reference types?

Value types inherit from the System.ValueType class, which in turn, inherits from System.Object. However, you can not inherit directly from theSystem.ValueType class. If you try to inherit explicitly from System.Value, you'll get the C3838compiler error. Value types have several special properties:

Value types are stored on the stack. (We'll discover that shortly.)

Value type objects have two representations: an unboxed form and a boxed form.

Value types are accessed directly which means you don't need to use the new operator.

Value types are managed types, they are initialised to 0 when they are created.

Value type instances are not under the control of the Garbage Collector.

Value types are implicitly sealed, which means that no class can derive from them.

In C#, structs are always value types and allocated on the stack.

Reference types inherit directly from System.Object, they offer many advantages over Value types:

Reference types are stored on the managed heap, thus they are under the control of Garbage Collector.

Two or more reference type variables can refer to a single object in the heap, allowing operations on one variable to affect the object referenced by the other variable.

The variable representing the instance contains a pointer to the instance of the class, it is dereferenced first if you want to access any of its members. In C#,Classes are always reference types and created on the managed heap.

23.What is concept of Boxing and Unboxing ?

Boxing and unboxing is a essential concept in C#’s type system. With Boxing and unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object. Boxing and unboxing enables a unified view of the type system wherein a value of any type can ultimately be treated as an object. Converting a value type to reference type is called Boxing. Unboxing is an explicit operation.
24.What is the difference between VB.NET and C#?

Difference between VB.NET and C#.
VB.NET :
1)no unsigned int
2)Loosely typed language
3)no operator overloading
4)no pointers
5)no auto XML documentation

C#.net :
1) supports unsigned int
2)strongly typed language
3)supports operator overloading
4)supports pointers
5)supports auto XML documentation

25.what is the difference between System exceptions and Application exceptions?

26.What is CODE Access security?

CAS is a security model that lets you grant or deny execution permissions to an assembly according to its "properties," called evidence, such as its strong name or publisher. CAS is completely orthogonal to classic security models that lie on the authentication-permissions mechanism based on the identity of the caller. This article is a concise introduction to this compelling and fascinating topic.

27.What is a satellite assembly?

Satellite Assembly Satellite assemblies are often used to deploy language-specific resources for an application. These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language. When uninstalling, the application removes only the satellite assemblies associated witha given language and .NET Framework version. No core .NET Framework files are removed

unless the last language for that .NET Framework version is being removed. For example, English and Japanese editions of the .NET Framework version 1.1 share the same core files.

The Japanese .NET Framework version 1.1 adds satellite assemblies withlocalized resources in a \ja subdirectory. An application that supports the .NET Framework version 1.1,

regardless of its language, always uses the same core runtime files

28.How to prevent my .NET DLL to be decompiled?

By design .NET embeds rich Meta data inside the executable code using MSIL. Any one can easily decompile your DLL back using tools like ILDASM (owned by Microsoft) or Reflector for.NET which is a third party. Secondly there are many third party tools which make this decompiling process a click away. So any one can easily look in to your assemblies and reverse engineer them back in to actual source code and understand some real good logic which can make it easy to crack your application .The process by which you can stop this reverse engineering is using “obfuscation”. It’s a technique which will foil the decompilers. There are many third parties (XenoCode, Demeanor for .NET) which provide .NET obfuscation solution. Microsoft includes one that is Dotfuscator Community Edition with Visual Studio.NET.

29.what is the difference between Convert.toString and .toString () method?

A. Convert.ToString wont allow null values. Cannot convert null to String

Whereas .ToString accepts null values

30.What is Native Image Generator (Ngen.exe)?

The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications. Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead using the just-in-time (JIT) compiler to compile the original assembly.

31. If we have two version of same assembly in GAC how do we make a choice?

32. What is CodeDom?

The CodeDOM provides types that represent many common types of source code elements. You can design a program that builds a source code model using CodeDOM elements to assemble an object graph. This object graph can be rendered as source code using a CodeDOM code generator for a supported programming language. The CodeDOM can also be used to compile source code into a binary assembly.

Some common uses for the CodeDOM include:

Templated code generation: generating code for ASP.NET, XML Web services client proxies, code wizards, designers, or other code-emitting mechanisms.

Dynamic compilation: supporting code compilation in single or multiple languages.

Comments

Popular posts from this blog

Decompiling Delphi - 3

Decompiling Delphi - 2

Artificial Intelligence, Oxymoron and Natural Intelligence