.Net Interview Questions - 1
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
-
What is What is a IL (MSIL or CIL), JIT?
(IL) stands for Intermediate Language and is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code is compiled to IL. This IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler.
-
What is a CTS?
In order that two language communicate smoothly CLR has CTS (Common Type System).Example: in VB you have “Integer” and in C++ you have "long" these datatypes are not compatible so the interfacing between them is very complicated. In order to able that two different languages can communicate Microsoft introduced Common Type System. So “Integer” datatype in VB6 and “int” datatype in C++ will convert it to System.int32 which is datatype of CTS. CLS which is covered in the coming question is subset of CTS.
-
What is a CLS(Common Language Specification)?
This is a subset of the CTS which all .NET languages are expected to support. It was always a dream of Microsoft to unite all different languages in to one umbrella and CLS is one step towards that. Microsoft has defined CLS which are nothing but guidelines that language to follow so that it can communicate with other .NET languages in a seamless manner.
-
What is a Managed Code?
Managed code runs inside the environment of CLR i.e. .NET runtime. In short all IL are managed code. But if you are using some third party software example VB6 or VC++ component they are unmanaged code as .NET runtime (CLR) does not have control over the source code execution of the language
-
What is a Assembly?
- Assembly is unit of deployment like EXE or a DLL.
- An assembly consists of one or more files (dlls, exe’s, html files etc.), and represents a group of resources, type definitions, and implementations of those types. An assembly may also contain references to other assemblies. These resources, types and references are described in a block of data called a manifest. The manifest is part of the assembly, thus making the assembly self-describing.
- An assembly is completely self-describing.An assembly contains metadata information, which is used by the CLR for everything from type checking and security to actually invoking the components methods. As all information is in the assembly itself, it is independent of registry. This is the basic advantage as compared to COM where the version was stored in registry.
- Multiple versions can be deployed side by side in different folders. These different versions can execute at the same time without interfering with each other. Assemblies can be private or shared. For private assembly deployment, the assembly is copied to the same directory as the client program that references it. No registration is needed, and no fancy installation program is required. When the component is removed, no registry cleanup is needed, and no uninstall program is required. Just delete it from the hard drive.
- In shared assembly deployment, an assembly is installed in the Global Assembly Cache (or GAC). The GAC contains shared assemblies that are globally accessible to all .NET applications on the machine
-
What are the different types of Assembly?
There are two types of assembly - private and public or shared assembly. A private assembly is normally used by a single application, and is stored in the application’s directory, or a sub-directory beneath. A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will find useful.
-
What is NameSpace?
Namespace solves 2 main problems:
- NameSpace logically groups types, for example System.Web.UI logically groups our UI related features.
- In Object Oriented world many times it’s possible that programmers will use the same class name.By qualifying NameSpace with classname this collision can be avoided.
-
What is Difference between NameSpace and Assembly?
- Assembly is physical grouping of logical units. Namespace logically groups classes.
- Namespace can span multiple assembly.
-
What is ILDASM ?
ILDASM stands for Intermediate Language Disassembler. To run ILDASM you have to go to “C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin” (For Windows XP and .Net 1.1). You might have to change it depending on the type of framework version you have. If you run ILDASM.EXE from the path you will be popped with the ILDASM exe program as shown in figure ILDASM. Click on file and browse to the respective directory for the DLL whose assembly you want to view. After you select the DLL you will be popped with a tree view details of the DLL as shown in figure ILDASM. On double clicking on manifest you will be able to view details of assembly, internal IL code etc as shown in Figure Manifest View.
-
What is Manifest?
Assembly metadata is stored in Manifest. Manifest contains following information
- Version of assembly.
- Security identity.
- Scope of the assembly.
- 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 stand-alone PE file that contains only assembly manifest information.
-
Where is version information stored of an assembly ?
It is stored in manifest.
-
Is versioning applicable to private assemblies?
No, it’s only applicable to the public assemblies stored in GAC.
-
What is GAC ?
GAC (Global Assembly Cache) is used where shared .NET assembly reside. GAC is used in the
following situations :- Assembly has to be shared among several application.
- Assembly has some special security requirements like only administrators can remove the assembly.
-
What is the strong name ?
Strong name is similar to GUID(It is supposed to be unique in space and time) in COM components.Strong Name is only needed when we need to deploy assembly in GAC. Strong Names helps GAC to differentiate between two versions. Strong names use public key cryptography (PKC) to ensure that no one can spoof it.PKC use public key and private key concept. 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.
-
What is use the of SN.EXE ?
The Strong Name tool helps sign assemblies with strong names. Sn.exe provides options for key management, signature generation, and signature verification.
-
How do you sign an assembly?
- Go to “Visual Studio Command Prompt”.
- After you are in command prompt type sn.exe -k “c:\test.snk”.
- After generation of the file you can view the SNK file in any editor, like notepad.
- In Visual Studio 2005, Go to Project\
properties\Signing and add path to the key file to the key selection field. - Compile the assembly.
-
How to add and remove an assembly from GAC?
There are two ways to install .NET assembly in GAC:
- Using Microsoft Installer Package. (Available for download on the Microsoft website)
- Using an utility Gacutil. Goto “Visual Studio Command Prompt” and type “gacutil –i (assembly_name)” to install or “gacutil –u (assembly_name)” to uninstall an assemby.
-
What is delay signing?
During development process you will need strong name keys to be exposed to developer which is not a good practice from security aspect point of view. In such situations you can assign the key later on and during development you an use delay signing
Following is process to delay sign an assembly:
- First obtain your string name keys using SN.EXE.
- Annotate the source code for the assembly with two custom attributes from System.Reflection: AssemblyKeyFileAttribute, which passes the name of the file containing the public key as a parameter to its constructor. AssemblyDelaySignAttribute,
which indicates that delay signing, is being used by passing true as a parameter to its constructor. For example as shown below:
[Visual Basic]
<Assembly:AssemblyKeyFileAttribute("myKey.snk")>
<Assembly:AssemblyDelaySignAttribute(true)>
[C#]
[assembly:AssemblyKeyFileAttribute("myKey.snk")]
[assembly:AssemblyDelaySignAttribute(true)]
The compiler inserts the public key into the assembly manifest and reserves space in the PE file for the full strong name signature. The real public key must be stored while the assembly is built so that other assemblies that reference this assembly can obtain the key to store in their own assembly.
- Because the assembly does not have a valid strong name signature, the verification of that signature must be turned off. You can do this by using the –Vr option with the Strong Name tool.The following example turns off verification for an assembly called myAssembly.dll.reference.
Sn –Vr myAssembly.dll
Comments
Leave a Reply
You must be logged in to post a comment.