You are on page 1of 9

.NET Framework Difference FAQs-1 1. What is the difference between CCW and RCW? S.

No 1 CCW Abbreviation: CCW stands for COM Callable Wrapper 2 Meaning: COM to .NET communication happens through CCW 3 Process involved for CCW: i)Create Assembly and compile with strong name. ii)Register Assembly using regasm iii)Register Assembly in GAC using gacutil /i iv)Use tlbexp to export Assembly as Type Library for COM. RCW Abbreviation: RCW stands for Runtime Callable Wrapper Meaning: .NET to COM Communication happens through RCW Process involved for RCW: i)Create Public Key Token file using sn.exe ii)Use tlbimp /keyfile: /out: iii)Register Imported Assembly in GAC using gacutil /i

2. What are the differences between DLL and EXE? S.No 1 2 3 4 DLL DLL stands for Dynamic Link Library DLL can not be used by End User. We can not run the DLL An ActiveX DLL runs in process server running in the same memory space as the client process. EXE EXE stands for Extensible Execute File EXE is used by End User like-Client We can run the EXE An ActiveX EXE is an out of process server which runs in it's own separate memory space.

If an unhandled error occurs it If an error occurs the client will cause the client process processes can continue to to stop operating. operate. DLL will run within an EXE DLL is an in-process file A DLL is visible to the system EXE can run independently EXE is an out-process file An EXE is visible to the

6 7 8

as a Win32 DLL but most likely without any entry points. The .NET runtime stores information about the contained assembly in its own header.

system as a regular Win32 executable. Its entry point refers to a small loader which initializes the .NET runtime and tells it to load and execute the assembly contained in the EXE.

3. What are the differences between Managed Code and Unmanaged Code? S.No 1 2 3 Managed Code It is executed under CLR It compiles to intermediate language It provides services like security, exception handling, garbage collection etc It can access both managed and unmanaged code Unmanaged Code It is not executed under CLR It compiles directly to machine code It does not provide security, exception handling, garbage collection etc It can access only unmanaged code

Reference: http://onlydifferencefaqs.blogspot.in/2012/07/net-framework-difference-faqs1_11.html DOTNET Framework Difference FAQs-2 1.Difference between Finalize() and Dispose() methods in .NET S.No 1 2 Finalize() Dispose()

Finalize() belongs to the Object Dispose() belongs to the class. IDisposable interface It is automatically called by the Garbage Collection mechanism when the object goes out of the scope(usually at the end of the program) We have to manually write the code to implement it(User Code) ex: if we have emp class we have to inherit it from the IDisposable interface and write code. We may have to suppress the Finalize method using GC.SuppressFinalize() method. Faster method for instant disposal of the objects. Example: user interface Controls. Forms, SqlConnection class have built in implementaion of Dispose method.

It is slower method and not suitable for instant disposing of the objects. Example: class employee {

//This is the destructor of emp class ~employee() { } //This destructor is implicitly compiled to the Finalize method. } 4 It is non-deterministic function i.e., it is uncertain when Garbage Collector will call Finalize() method to reclaim memory. It is deterministic function as Dispose() method is explicitly called by the User Code.

2.Difference between Dispose and Destructor in .NET S.No 1 Dispose Unmanaged resources are removed by dispose method and it is called manually It is used to remove the unused resources from the memory. Destructor It is used to release unused managed resources and it is called automatically by the Garbage Collector It is used to de-allocate the allocated memory by the constructor method

3.Difference between Close() and Dispose() methods in .NET S.No 1 Close() When a Close() method is called,database connection will be temporarily closed and can be opened once again using Open() method. Dispose() Where as Dispose() method permanently close and removes connection object from memory and the resource no longer exists for any further processing. Note: However, calling Dispose does not remove the connection from the connection pool. Example: try {

string constring = "Server=(local);Database=my; User Id=sa; Password=sa"; SqlConnection sqlcon = new SqlConnection(constring); sqlcon.Open(); // here connection is open // some code here which will be execute } catch { // code will be execute when error occurred in try block } finally { sqlcon.Close(); // close the connection sqlcon.Dispose(); // desroy the connection object } Note: Only call the Close method on a Stream or a database connection if the object will be reused. Otherwise, use the Dispose method. Reference: http://onlydifferencefaqs.blogspot.in/2012/08/dotnet-framework-differencefaqs-2.html DOTNET Framework Difference FAQs-3 1.Difference between Namespace and Assembly S.No 1 Namespace Assembly

Namespace is the logical Scope for a particular type is naming decided at design time defined at run time using Assembly. by the developer. Namespace contains set of Assembly contains code of the unique names. form MSIL ( Microsoft Intermediate Language) Classes available in your Logical units are physically program will be logically grouped together as assembly. grouped together under a namespace. Namespace can multiple assemblies. include An assembly can contain types belonging to different namespaces.

4 5

Namespace doesn't have any Assembly can be classified as classification. private assembly and public assembly. Private assembly is specific to a single application but shared/public assembly contains libraries which can be used by

multiple applications. 6 Namespaces mentioned Properties. have in to be Assemblies need not be explicitly Project- specified. They are automatically described in metadata and manifest files.

Namespaces can be nested. Such nesting is not permissible in For example: assemblies. namespace sampleApp1 { namespace SampleApp2 { class sampleClass { } } } Namespace is the one which you directly specify in your code. A simple example for namespace is shown below: namespace sampleNamespace { class sampleClass { public void displayMsg() { Console.WriteLine("In sampleClass"); } } } In this example, sampleNamespace is the namespace you have created and sampleClass is within the scope of this namespace. Creating an assembly on your own is not as simple as you create a namespace. If you want to package the code shown as an example for the namespace into an assembly, then you have to follow the steps shown below: " Generate a key file inside the same folder where you have placed the code by typing the following statement in the command prompt: sn -k sampleKey.key " Sign your code component with this key. Assume that your code component is named as sampleClass.cs. Now use the following command: csc sampleClass.cs /t:library /a.keyfile:sampleKey.key " Place your signed assembly inside GAC using AL Utility: AL /i: sampleClass.dll " Now create a code that accesses the code in your assembly: Using System; Using sampleNamespace; public class testClass { sampleClass obj = new sampleClass(); obj.displayMsg(); } " To test if your assembly got created and to test if the above code is working, compile the above

code using the following statement: csc testClass.cs /t:exe /r: " Now if you execute testClass.cs, you should get the following output: In sampleClass 2.Difference between System Exception and Application Exception S.No 1 2 System Exception CLR throws system exception Application Exception Application exception throws application

System exceptions are generic Application exceptions are not in nature generic. Each application exception has its own customized meaning Each system exception has a meaning. You can directly use them or you can derive new ones by inheriting System.Exception Application exceptions do not have a meaning for themselves. You have to explicitly derive from them and create your own custom exceptions specific to your application

Example for system exceptions Example for application exceptions include SqlException, include SharePointException, StackOverflowException CmsException

3.Difference between COM and .NET Component S.N o 1 2 3 4 COM Component Interface communication .NET Component based Object based communication Collector to manage

Reference count will be used Garbage to manage memory memory Binary Standard objects Objects are created coCreateInstance

Type Standard objects by Objects are created by normal new operator

5 6

Object info resides in Type Object info resides in assembly library files HRESULT will be returned Exceptions will be returned COM=HRESULT will be returned

4.Difference between Private Assembly and Public Assembly

S.N o 1 2

Private Assembly Private assembly can be used by only one application. Private assembly will be stored in the specific application's directory or sub-directory. There is no other name for private assembly.

Public Assembly Public assembly can be used by multiple applications. Public assembly is stored in GAC (Global Assembly Cache). Public assembly is also termed as shared assembly.

3 4 5 6

Strong name is not required for Strong name has to be created for private assembly. public assembly. Private assembly doesn't have Public assembly should any version constraint. enforce version constraint. By default, all assemblies you create are examples of private assembly. Only when you associate a strong name to it and store it in GAC, it becomes a public assembly. strictly

An example to public assembly is the actuate report classes which can be imported in the library and used by any application that prefers to implement actuate reports.

Reference: http://onlydifferencefaqs.blogspot.in/2012/08/dotnet-framework-differencefaqs-3.html Weak-named vs Strong-named .NET components Difference between Weak-named .NET components and Strong-named .NET components S.No 1 Weak-named .NET components Weak names are not guaranteed to be unique and thus cannot be shared without potentially causing conflicts. Weak-named .NET components must be individually copied to the /bin directories of the Web applications where they are used. .NET components with weak names can call unmanaged Strong-named .NET components Strong names are digitally signed and provide a public key that ensures there are no conflicts. Strong-named .NET components can be copied into the servers GAC

Furthermore, .NET components with strong names cannot call

code (such as COM components) and thus causes potential conflicts with dependencies.

unmanaged code (such as COM components) and thus avoid potential conflicts with dependencies.

Reference: http://onlydifferencefaqs.blogspot.in/2012/08/difference-between-weaknamed-net.html Difference between STA and MTA Difference between STA and MTA S.No 1 2 STA STA stands for Single Threaded Apartment In STA,there may be multiple apartment.But only single thread can be executed in a apartment. In STA, if there is a need to communicate between threads we need a proxy, they can not do it directly. MTA applications execute slower than STA MTA MTA stands for Multi Threaded Apartment In MTA, only one apartment will be there and all threads will execute within that single apartment. In MTA, threads communicate directly to each other without a proxy. MTA applications typically execute faster than STA because there is less system overhead and can be optimized to eliminate system idle time. If the COM object can handle its own synchronization then the MTA model can be used

If the COM object cannot handle its own synchronization i.e not thread safe then the STA model can be used

Summary: An apartment is a logical container within a process for objects sharing the same thread access requirements. All objects in the same apartment can receive calls from any thread in the apartment. The .NET Framework does not use apartments, and managed objects are responsible for using all shared resources in a thread-safe manner themselves. Reference: http://onlydifferencefaqs.blogspot.in/2012/08/difference-between-sta-andmta.html

Assembly.CreateInstance() vs Activator.CreateInstance() Difference between Assembly.CreateInstance() and Activator.CreateInstance() S.No 1 Assembly.CreateInstance() Activator.CreateInstance()

Namespace: Namespace: Derives from Derives from System namespace. System.Reflection namespace. Meaning: Locates a type from this assembly and creates an instance of it using the system activator.In simple terms, Assembly.CreateInstance looks for a type in a particular assembly. Does it have overload method to create objects in other app domains, or on another server ? Assembly.CreateInstance Method does not have overload method to create objects in other app domains, or on another server using Remoting as like Activator.CreateInstance Method. Meaning: Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly and default constructor.In simple terms, Activator.CreateInstance can create an object of any type. Does it have overload method to create objects in other app domains, or on another server ? Activator.CreateInstance has overloads that Assembly.CreateInstance Method does not have;for instance, it can create objects in other app domains, or on another server using Remoting.

Reference: http://onlydifferencefaqs.blogspot.in/2012/09/assemblycreateinstance-vs.html

You might also like