8.08.2012

DOTNET Framework Difference FAQs-3

1.Difference between Namespace and Assembly
S.No
Namespace
Assembly
1
Namespace is the logical naming decided at design time by the developer.
Scope for a particular type is defined at run time using Assembly.
2
Namespace contains set of unique names.
Assembly contains code of the form MSIL ( Microsoft Intermediate Language)
3
Classes available in your program will be logically grouped together under a namespace.
Logical units are physically grouped together as assembly.
4
Namespace can include multiple assemblies.
An assembly can contain types belonging to different namespaces.
5
Namespace doesn't have any classification.
Assembly can be classified as 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 have to be mentioned in Project-Properties.
Assemblies need not be explicitly specified. They are automatically described in metadata and manifest files.
7
Namespaces can be nested. For example:
namespace sampleApp1 {
namespace SampleApp2 {
class sampleClass {

}
}
}
Such nesting is not permissible in assemblies.
8
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
System Exception Application Exception
1
CLR throws system exception
Application throws application exception
2
System exceptions are generic in nature
Application exceptions are not generic. Each application exception has its own customized meaning
3
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
4
Example for system exceptions include SqlException, StackOverflowException
Example for application exceptions include SharePointException, CmsException
3.Difference between COM and .NET Component
S.No
COM Component .NET Component
1
Interface based communication
Object based communication
2
Reference count will be used to manage memory
Garbage Collector to manage memory
3
Binary Standard objects
Type Standard objects
4
Objects are created by coCreateInstance

Objects are created by normal new operator

5
Object info resides in Type library
Object info resides in assembly files
6
HRESULT will be returned
Exceptions will be returned     
COM=HRESULT will be returned
4.Difference between Private Assembly and Public Assembly
S.No
Private Assembly Public Assembly
1
Private assembly can be used by only one application. Public assembly can be used by multiple applications.
2
Private assembly will be stored in the specific application's directory or sub-directory.
Public assembly is stored in GAC (Global Assembly Cache).
3
There is no other name for private assembly. Public assembly is also termed as shared assembly.
4
Strong name is not required for private assembly.
Strong name has to be created for public assembly.
5
Private assembly doesn't have any version constraint.
Public assembly should strictly enforce version constraint.
6
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.
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.

1 comment:

  1. very nice,but if any one gives some more explaination it will some more better to under stand.thanks... Hire .Net Developers India

    ReplyDelete