Dot Net Framework

1. What is .NET Framework?
Dot Net Framework is an environment for building, running, deploying Web Applications, Desktop Applications & Web services. Dot Net Framework is an API for building applications on windows.

The .NET Framework has two main components: Common Language Runtime (CLR) and Framework Class Library (FCL).
CLR is an agent that manages code at execution time, providing core services such as memory management, thread management, remoting, code verification, compilation, and other system services, also enforcing strict type safety.
FCL is an Object-Oriented collection of reusable types that we can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET such as Web Forms and XML Web services.

2. What are CLR, CTS, and CLS?
The .NET Framework provides a runtime environment called the Common Language Runtime or CLR (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.
The managed code that targets CLR benefits from useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support and debugging.

Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety and high performance code execution.
The CTS Specification defines all possible Datatypes and Programming constructs supported by the CLR and how they may or may not interact with each other. Because of this feature, the .NET Framework supports development in multiple programming languages.

Common Language Specification(CLS) is simply a specification that defines the rules to support language integration in such a way that programs written in any language can interoperate with one another taking full advantage of inheritance, polymorphism, exceptions and other features.

What is common language Specification?What is difference between CTS and 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).
The CTS defines the rules concerning data types.
Any program which uses CLS-compliant types can interoperate with any .NET program written in any language.
C# supports both CLS and CTS.


3. Is .NET a runtime service or a development platform?
Ans: It's both. .NET framework’s SDK consists of two parts: the .NET common language runtime and the .NET class library. SDK also includes command-line compilers for C#, C++, JScript, and VB. We use these compilers to build applications and components. These components require the runtime to execute so .Net is development and runtime platform.

4. What is MSIL?
While compiling managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations.
Microsoft intermediate language (MSIL) is a language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler. The common language runtime includes a JIT compiler for converting MSIL to native code.
Can I do things in IL that I can't do in C#?
Yes. A couple of simple examples are that we can throw exceptions that are not derived from System.Exception and can have non-zero-based arrays.

5. What is strong name?
A name that consists of an assembly's identity which includes text name, version number, and culture information (if provided).

6. 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.

7. Which namespace is the base class for .net Class library?
Ans: system.object

8. Why do I get errors when I try to serialize a Hashtable?
XmlSerializer will refuse to serialize instances of any class that implements IDictionary, e.g. Hashtable. SoapFormatter and BinaryFormatter do not have this restriction.

9. What are the contents of assembly?
In general, a static assembly can consist of four elements:
1. The assembly manifest, which contains assembly metadata.
2. Type metadata.
3. Microsoft intermediate language (MSIL) code that implements the types.
4. A set of resources.

10. What are the different types of assemblies?
Private, Public/Shared, Satellite

11. What is serialization in .NET? What are the ways to control serialization?
Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes.
Serialization/Deserialization is mostly used to transport objects during remoting. Serialization can be defined as the process of storing an object’s state to a storage medium. During this process, public and private fields of the object, name of the class, including the assembly containing the class are converted to a stream of bytes which is then written to a data stream. When the object is deserialized, an exact clone of the original object is created.
• Binary serialization preserves type fidelity, which is useful for preserving the state of an object.
• XML serialization serializes only public properties and fields and does not preserve type fidelity. This is useful when we want to provide or consume data without restricting the application that uses the data.
There are two separate mechanisms provided by the .NET class library - XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting.

12. Define Assembly. How many types of assemblies are there?
Assembly is a collection of compiled or executable components which is versioned and deployed as single implementation unit.
Assemblies are the fundamental unit of deployment, version control, reuse and security permissions for a .NET-based application. Assemblies take the form of an executable (.exe) file or dynamic link library (.dll) file, and are the building blocks of the .NET Framework.
All managed types and resources are contained within an assembly and are marked either as accessible only within the assembly or as accessible from code in other assemblies.
Assemblies can be static or dynamic. Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in PE files. You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.

Assemblies are of three types
1. Private assembly- can be accessed only by single application and is stored in the application's directory
2. Shared assembly-can be accessed by multiple applications in a system and is stored in the global assembly cache.
3. Satellite assemblies- are used to deploy language-specific resources for an application and are stored in a language-specific subdirectory for each language.

13. In .NET Compact Framework, can I free memory explicitly without waiting for garbage collector to free the memory?
Yes, you can clear the memory using gc.collect method but it is recommended that u should not call this coz we don’t know the exact time when the GC will be called automatically.
In Dot net u cannot explicitly call a garbage collector; it can be called through CLR.

14. How can I change private assembly to shared assembly?
Yes, you can change from Private to Shared.
- Get the SN using sn.exe?
- Add the SN to the Assembly
- Put the Assembly in GAC.

16. How many classes can a single .NET DLL contain?
Unlimited

18. What is a Manifest?
Manifest describes the assembly itself, providing the logical attributes shared by all the modules and components in an assembly.
The manifest contains the assembly name, version number, locale and an optional strong name that uniquely identifies the assembly. This manifest information is used by the CLR.

19. What is a Metadata?
Metadata is used to describe other data. Data definitions are sometimes referred to as metadata. Examples of metadata include schema, table, index, view and column definitions.

Metadata is information stored in the assembly that describes the types and methods of the assembly and provides other useful information about the assembly. Assemblies are said to be self-describing because the metadata fully describes the contents of each module.

20. What is a Strong Name?
A strong name is a way to ensure that a shared assembly's name does not conflict with another shared assembly.
A strong name contains assembly name, a public key and a private key.
For installing an assembly into GAC you need to give it a strong name. First generate a key pair using 'sn.exe' command line utility and write the key file name as AssemblyKeyFileAttribute in a code file of the assembly.

21. Creating a Key Pair
To create a key pair uses the dot net command line tool sn.exe
sn.exe -k mykey.snk
This filename is used as the attribute value for AssemblyKeyFileAttribute in one of the code files of assembly. It generates a strong named assembly which could be installed into the GAC.

22. What is GAC?
GAC stands for Global Assembly Cache. It is used for storing shared assemblies. It stores all versions of a particular assembly so that on updating an assembly the existing applications which use the earlier version do not break.
For storing an assembly into the GAC you need to sign the assembly with a strong name. For this purpose follow these steps:
1. Use sn.exe command line utility to generate a key pair
2. Add the key file name to the assembly as value for AssemblyKeyFileAttribute.
3. Build the assembly.
4. Use gacutil.exe -i command on the command prompt to install it in the cache.

23. What is Reflection?
Reflection is a namespace in .net which allows you to access metadata for loaded types and objects.
It also allows you to create new types and their objects at runtime.
Reflection is the process by which a program can read its own metadata or metadata from another program. A program is said to reflect on itself or on another program, extracting metadata from the reflected assembly and using that metadata either to inform the user or to modify the program's behavior.
For the attributes in the metadata to be useful, you need a way to access them, ideally during runtime. The classes in the Reflection namespace, along with the System.Type class, provide support for examining and interacting with the metadata.
Reflection is generally used for any of four tasks.

Viewing metadata
This might be used by tools and utilities that wish to display metadata.

Performing type discovery
This allows you to examine the types in an assembly and interact with or instantiate those types. This can be useful in creating custom scripts. For example, you might want to allow your users to interact with your program using a script language, such as JavaScript, or a scripting language you create yourself.

Late binding to methods and properties
This allows the programmer to invoke properties and methods on objects dynamically instantiated, based on type discovery. This is also known as dynamic invocation.

Creating types at runtime (reflection emit)
The ultimate use of reflection is to create new types at runtime and then to use those types to perform tasks. You might do this when a custom class, created at runtime, will run significantly faster than more generic code created at compile time.

24. What are Attributes?

Attributes are part of metadata for a class.
Attributes are used to specify assembly information like key file name, or for specifying security related information. You can create new attributes for your specific needs or ideas.
Attributes are a mechanism for adding metadata, such as compiler instructions and other data about your data, methods, and classes, to the program itself. Attributes are inserted into the metadata and are visible through ILDasm and other metadata- reading tools.

25. When is Marshalling not necessary?
Marshalling is the process of packaging and sending interface method parameters across thread, process or machine boundaries.
When Ever component runs with in client App Domain process then marshalling is not necessary. Marshalling is nothing but gathering or packaging the information into message for transferring across the network required in distributed environment.

26. What is JIT (just in time)? How it works?
When Assembly is executed for the first time on a new computer,the IL will be compiled into machine language optimized for the machine's language which is called as JIT(Just-In-Time Compilation).

27. What is Application Domain?

The primary purpose of the AppDomain is to isolate an application from other applications. Win32 processes provide isolation by having distinct memory address spaces.
All memory in the AppDomain is managed by the .NET runtime, so the runtime can ensure that AppDomains do not access each other's memory.

Objects in different application domains communicate either by transporting copies of objects across application domain boundaries, by using a proxy to exchange messages.

MarshalByRefValue When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries.


MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy.


28. What is the managed and unmanaged code in .net?

Code that you develop with a language compiler that targets the runtime is called managed code; it benefits from features such as cross-language integration, cross-language exception handling, enhanced security, versioning and deployment support.

29. How do you create threading in .NET? What is the namespace for that?
System.Threading.Thread
30. Describe the Managed Execution Process?
> Choosing a compiler.
> Compiling your code to Microsoft intermediate language (MSIL).
> Compiling MSIL to native code.
> Executing your code.

31. What are Namespaces?
The namespace keyword is used to declare a scope. This namespace scope lets us organize code and gives you a way to create globally-unique types. Even if you do not explicitly declare one, a default namespace is created.

No comments: