1. What is mean by .Net Framework?
The .NET framework is a collection of all the tools and utilities required to execute the .NET managed applications on a particular platform.
2. What is mean by CLR?
Common Language Runtime is the core component of .Net framework. It is similar to the Java Virtual Machine or JVM in Java, which handles the execution of code and provides useful services for the implementation of the program. It provides a number of services, including the following
- management (loading and execution)
- Application memory isolation
- Verification of type safety
- Conversion of IL to native code
- Access to metadata (enhanced type information)
- Managing memory for managed objects
- Enforcement of code access security
- Exception handling, including cross-language exceptions
- Interoperation between managed code, COM objects, and pre-existing DLLs (unmanaged code and data)
- Automation of object layout
- Support for developer services (profiling, debugging, and so on)
3. What is difference between managed and unmanaged code?
The managed code is always executed by a managed runtime execution environment like CLR for .Net. Metadata information of the code will be exchanged with runtime, so runtime environment can guarantee what the code is going to do and provide the necessary security checks before executing any piece of code
Code that is directly executed by the Operating System is known as un-managed code. Example applications written in VB 6.0, C++, C, etc are unmanaged code that typically targets the processor architecture and is always dependent on the computer architecture. In unmanaged code the memory allocation, type safety, security, etc needs to be taken care of by the developer.
4. What is mean by MSIL?
MSIL or IL stands for Microsoft Intermediate Language; if you compile managed code, the compiler translates your source code into Microsoft intermediate language. MSIL is platform independent language which can be converted to native code while installing software or at runtime by using Just-in compiler.
5. What is mean by CTS?
Common type system defines how types are declared, used, and managed in the runtime, and is also an important part of the runtime's support for cross-language integration. CTS is responsible for defining types that can be used across the .Net Languages. CTS Provides the data types, values, object types. This helps developers to develop applications in different languages.
For example, an integer variable in C# is written as int, whereas in VB.Net it is written as integer. Therefore in .Net Framework you have single class called System.Int32 to interpret these variables.
6. What is mean by CLS?
Common Language Specification is the subset of CTS; it is specification that defines the set rules and guidelines that all supporting language should follow. It integrate in such a way that programs written in any language can interoperate with one another.
7. What is mean by JIT?
Just In Time(JIT) compilers which compile the IL code to native executable code (.exe or .dll) for the specific machine and OS. JIT are slightly different from traditional compilers as they compile the IL to native code only when desired e.g., when a function is called, IL of function's body is converted to native code; just in time of need. If same function is called next time, the CLR uses the same copy of native code without re-compiling. As JIT are aware of processor and OS exactly at runtime, they can optimize the code extremely efficiently resulting in very robust applications.
8. What are different types of JIT?
Pre-JIT - Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.
Econo-JIT - Econo-JIT compiles only those functions that are called at runtime. However, these compiled functions are removed when they are not required.
Normal-JIT - Normal-JIT compiles only those functions that are called at runtime and they are stored in cache. If same function is called next time, the CLR uses the same copy of compiled code without re-compiling.
9. What is mean by Assembly?
- Assemblies are self-describing installation units, consisting of one or more files.
- Assemblies are the deployment units of .Net applications. .Net application consists of one or more assemblies.
- An assembly may also contain references to other assemblies and it include metadata that describes all the types that are defined in the assembly with information about it members-methods, properties, events and fields.
- One assembly could be a single Dll or exe that includes metadata, or it can be made of different files e.g resource files, modules and an exe.
- Assembly manifests is a part of the metadata, it describes the assembly with all the information that's needed to reference it and lists all its dependencies.
10. What are the features of Assembly?
- Assemblies are self-describing, it includes metadata that describes the assembly. It does not required to register key as like COM component.
- Version dependencies are recorded inside an assembly manifest. The version of the referenced assembly that will be used can be configured by the developer and the system administrator.
- Two different version of same assembly can be used inside single process.
11. What are different type's assemblies?
Private assembly- Private assembly is used within your application and it is installed at the same time as the application itself. It will be located in the same directory as the application or subdirectories thereof.
Shared assembly- Shared assemblies are used by several application. Shared assembly must have version number and unique name and it is usually installed in GAC (Global assembly catch). It reduces the need for disk space and memory space.
12. What are parts of assembly manifests?
- Identity - Name, version, culture and public key
- A list of files - Files belonging to the assembly, it can have one or more files.
- Lists of referenced assemblies - all assemblies referenced by the assembly are documented inside the manifest.
- Set of permission requests- these are the permission needed to run the assembly.
- Exported types - It describes the structures, class with properties, method and events. It is used to create instance of the class.
13. What is mean by Namespace?
Namespace Logically group classes, it avoids name clashes between classes.
Example : most of the general purpose .net base classes are in a namespace called System. The base class Array is in this namespace is accessed with full name System.Array.
14. What is difference between Assembly and Namespace?
- Assembly is physical grouping of classes. Namespace logically groups classes.
- Single assembly can have different namespaces
- Sample namespace can be used in different assembly. E.g the assembly mscorlib and system contain the namespace System.Threading
15. What is the difference between an executable assembly and a class library?
An executable assembly exists as the .exe file while a class library exists as the .dll file. Executable assembly represent executable applications having some entry (e.g., Main() method in C#). A class library, on the other hand, contains components and libraries to be used inside various applications. A Class library cannot be executed and thus it does not have any entry point.
16. What is ILDASM?
ILDASM(Intermediate Language DisAssembler ), this is inbuild tool to view content and manifest of the assembly. We can run the ILDASM by running following exe "C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\ildasm.exe"
17. What is mean by Manifest?
Manifest is used to describe the information about the assembly, it contains following information.
- Assembly name - Aids in versioning and visibility scope.
- Version information - The version number is integrated into the assembly's identity.
- Types - Boundaries and scopes of methods, classes, properties, events and attributes.
- Locale - Information describing language/culture.
- Reference - provides information for type references in an assembly and other referenced assemblies.
- Cryptographic Hash - Public key encoded hash acting as version/security check.
- Security Permissions - The permissions within the assembly determine the permissions that can be granted for all aspects of the assembly contents.
18. How will you created shared assembly?
Shared assembly can be created by signing the assembly. Sets to created shared assembly
- Create new class library project using visual studio
- Navigate to the property page of the class library
- Select "Signing" tab
- Select "Sign the assembly" check-box
- Now select < New >... from "Choose a strong name key file" dropdown
- Enter new Signing key file name and click Ok
- Next the build the project. Now the shared assembly is ready to use in different project.
19. What is the use of Shared Assembly?
If you want to use the same assembly in different projects, we can create a shared assembly and placed inside the GAC(Global assembly Catch). So that assembly is access by all the application. Private assembly also be used in different projects, but we need to copy the private assembly files to different application folder. But if we are using Shared assembly, the assembly file remains in single location.
Shared assembly is highly secured, only administrator can uninstall the shared assembly.
20. What is GAC?
GAC(Global assembly catch) is used to store .Net assembly. It is located in "C:\Windows\assembly"
21. What is mean by Delay signing?
During development process, usually private key will not be exposed to the developer due to security reason. In this kind of scenario, we will go with delay signing.Delay signing allows you 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.
E.g
VB.Net(Assemblyinfo.vb)
< Assembly: AssemblyKeyFileAttribute("myKey.snk") >
< Assembly: AssemblyDelaySignAttribute(True) >
C#(Assemblyinfo.cs)
[assembly: AssemblyKeyFileAttribute("myKey.snk")]
[assembly: AssemblyDelaySignAttribute(true)]
22. What is mean by Satellite assembly?
When we write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.
23. What is portable executable (PE)?
The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.
24. What is mean by Garbage collection?
Garbage collection is a CLR features used to automatically manages memory. CLR automatically release the objects which are not longer used or referenced. Developer who forget to release the dispose the objects will be cleared by GC. But it is not known when GC will be called by CLR to clean the memory. So better we can dispose the objects once it is used.
25. What are the different levels of GC is available?
Generation 0 , Generation 1, Generation 2
26. How Garbage collector will get memory from OS?
When execution engine starts, GC will initialize segment of memory for its operation. GC reserves memory in segment, each segment is 16MB. When we run out of segments we reserve a new segment. If a segment of memory is not in use, it will be deleted.
27. What is mean by LOH?
LOH-(Large Object Heap). If size of the object are very high(>64KB) then it will be stored in different segment of memory called as LOH. GC will treat the large objects differently from small objects.
28. What are situations GC will be called?
- If user forcefully calls System.GC.Collect
- System is in low memory situation
- Memory allocation exceeds the Generation0 threshold
29. What is mean by value type and Reference type?
Value type- Value type stores their value directly to memory address. Value type's values are allocated on the stack memory.
Reference type - Reference type stores the reference to the value's memory address. Reference type values are allocated on head memory.
30. What is mean by Boxing and Unboxing?
Boxing - Converting value type variable to reference type is called as boxing
UnBoxing - Converting reference type variable to value type is called as unboxing
int vType = 35;
object rType;
//Boxing process
rType = vType;
//Unboxing process
vType =(int) rType;
31. How will you decide when to use value type and reference type?
All depends upon need.
32. What is difference between System exception and Application exception?
All exceptions are derived from the Exception base class. Where Exception class is derived from the Object class. Both System and Application exception are derived from exception class but it has difference between them. System exceptions are thrown by the CLR where as Application exceptions are thrown by Application.
System Exception
Application Exception
System exceptions are thrown by CLR
Application exceptions are thrown by Application
E.g OutOfMemoryException, NullReferenceException,etc
E.g User defined exception are created to throw application's exception and user defined exceptions are derived from ApplicationException
33. What is Reflection?
.Net compilers store metadata information(types defined) about the assemblies inside the assembly itself. Using this metadata we can load an assembly dynamically (at runtime), get information about its containing types, instantiate these types and call methods.
"Reflection" is a mechanism using which we can load an assembly dynamically and call its method. The System.Reflection is the root namespace that contains classes to implement the reflection. The Assembly class is the one which is used to represent the assembly in .Net environment.
Example:
static void Main(string[] args)
{
// Load an assembly from file
Assembly myAssembly = Assembly.LoadFrom("MyService.dll");
// Get the types contained in the assembly and print their names
Type[] types = myAssembly.GetTypes();
foreach (Type type in types)
{
Console.WriteLine(type.FullName);
//Get the members(methods) present inside each type
foreach (MemberInfo member in type.GetMembers())
{
Console.WriteLine(" "+member.Name);
}
}
Console.ReadLine();
}
OutPut:
34. How will you decompile your assembly?
Any assembly can be disassembled using ILDASM(Intermediate Language Disassembler), it is ships with the .Net framework SDK. Using third party tools like Reflector or Anakrino can also be easily decompile the assemblies.
35. What is mean by Obfuscation?
Obfuscation is a technique used to mangle symbols and rearrange code blocks to foil decompiling. Dotfuscator, is a popular obfuscation package ships with Visual Studio.
36. If we have two different version of same assembly in GAC how do we make a choice?
Let us consider the scenario where one of the applications uses the dll which is available in GAC. Now we are creating the second version of the same dll and placed inside the GAC. So GAC contains both version of the assembly, since application referring the dll from GAC, definitely it will take latest version of the dll. But we need old version of the assembly to be executed. How to achieve this requirement?
Answer: using < bindingRedirect > tag in App.config file
Example:
Step 1: Create sample library class with MyVersion() method. This method will return current version of the assembly.
namespace AssemblyVersionExample
{
public class Class1
{
public string MyVersion()
{
return "The old version: 1.0.0.10";
}
}
}
Step 2:Modify the "AssemblyVersion" attribute with the old version say ‘"1.0.0.10"
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.10")]
[assembly: AssemblyFileVersion("1.0.0.10")]
Step 3:Compile the dll and register to assembly using "gacutil"
Step 4:Create a public token key using following command [ sn -T "filepath"]. Now the public key for the assembly is created.
Step 5:Repeat the step 2,3 with different version for same assembly
public string MyVersion()
{
return "The new version: 1.0.0.20";
}
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.20")]
Step6: Now let's start creating the application, which refer the AssemblyVersionExample.dll Create a instance of the class and invoke the method. Output of the assembly will be new version.
static void Main(string[] args)
{
AssemblyVersionExample.Class1 objClass = new AssemblyVersionExample.Class1();
Console.WriteLine(objClass.MyVersion());
Console.ReadLine();
}
Step 7: Since we need to use the old version of the assembly from GAC, we should make use of "bindingRedirect" tag in the application. In the below sample, you can find that new attribute is set with old version value (newVersion="1.0.0.10") and attribute is set with new version value (oldVersion="1.0.0.20"). When we execute the application, resultant output will be from old version of the dll.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="AssemblyVersionExample"
publicKeyToken="7c779e284ebe2e8c"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.20"
newVersion="1.0.0.10"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Output:
37. What is mean by Dll Hell?
DLL hell means deploying the same DLL in your application multiple times. In windows application dlls are shared across multiple application. Suppose when App1 is using MyAssembly.dll and it is working fine. Suppose I am installing new application App2 which also having assembly MyAssembly.dll, while installing App2 it will override the old assembly with new MyAssembly.dll. Now only App2 will function properly where as App1 which depends on MyAssembly.dll will fail. This is called as Dll hell. It can be solved by assembly versioning.
38. How's the DLL Hell problem solved in .NET?
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.
39. What's the difference between the System.Array.CopyTo() and System.Array.Clone()?
- System.Array.CopyTo() - Performs a deep copy of the array
- System.Array.Clone()- Performs a shallow copy of the array
40. What is difference between application running in Debug and Release mode?
In a debug build mode the complete symbolic debug information is added to complile assembly to help while debugging applications and also the code optimization is not taken into account. While in release build the symbolic debug infrmation is not added to the compiled assembly and the code execution is optimized. Since debuging information is not added in a release build, the size of the final executable is lesser than a debug executable.
41. What is the difference between traditional development and .NET development?
In traditional programming languages, the source code of a program is compiled to a specific platform's assembly language and then machine language code. Later the library code required by the program is linked to it. Finally the operating system executes the program when desired by the user
In the presence of dot net framework, a program is not compiled to the native machine executable code; rather it gets compiled to an intermediate language code called Microsoft Intermediate Language (MSIL) or Common Intermediate Language (CIL). The Dot Net Common Language Runtime (CLR) then converts this intermediate code at runtime to the machine executable code. The optimization is carried out at runtime
41. How true it is that .NET and Java programs are quite in-efficient when compared to C++?
In .Net and Java programming, initial execution of the program will be little bit slower than the C++ programming. Because .Net and Java involves the hosting of CLR into managed applcaiotn process in .Net and starting the JVM in a new process in case of Java. Since, the CLR and JVM optimizes the code more efficiently than the static C++ compilers, the execution speed of the program may actually be faster after sometime of the program startup when most of the code is translated. Hence, in the longer run, the .Net and Java based programs should not be in-efficient when compared to C++.
42. How Finaliz() method will work in .net?
.Net framework provides ahte Object.Finalize() method to clean up objects unmanaged resources. In general garbage collector keeps track of objects that have Finalize methods, using an internal structure called the finalization queue. Each time your application creates an object that has a Finalize method, the garbage collector places an entry in the finalization queue that points to that object. The finalization queue contains entries for all the objects in the managed heap that need to have their finalization code called before the garbage collector can free their memory.
Finalize methods requires at least two garbage collections to free the resources. When the garbage collector performs a collection, it reclaims the memory for inaccessible objects without finalizers. At this time, it cannot collect the inaccessible objects that do have finalizers. Instead, it removes the entries for these objects from the finalization queue and places them in a list of objects marked as ready for finalization. Entries in this list point to the objects in the managed heap that are ready to have their finalization code called. The garbage collector calls the Finalize methods for the objects in this list and then removes the entries from the list. A future garbage collection will determine that the finalized objects are truly garbage because they are no longer pointed to by entries in the list of objects marked as ready for finalization. In this future garbage collection, the objects' memory is actually reclaimed.