You are on page 1of 3

1.Difference between Namespace and Assembly S.

No 1 Namespace Assembly

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

4 5

Namespaces have to be mentioned Assemblies need not be explicitly in Project-Properties. specified. They are automatically described in metadata and manifest files. Namespaces can be nested. For Such nesting is not permissible in 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"); } } } 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

In this example, sampleNamespace is the namespace you have created and sampleClass is within the scope of this namespace.

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:<path of your assembly> " 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 in Application exceptions are not generic. nature 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.No 1 2 3 4

COM Component Interface based communication

.NET Component Object based communication

Reference count will be used to Garbage Collector to manage memory manage memory Binary Standard objects Objects are coCreateInstance created Type Standard objects by Objects are created by normal new operator Object info resides in assembly files Exceptions will be returned COM=HRESULT will be returned

5 6

Object info resides in Type library HRESULT will be returned

4.Difference between Private Assembly and Public Assembly S.No 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. Strong name is not required 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. Strong name has to be created for public assembly.

3 4 5 6

Private assembly doesn't have any Public assembly should strictly enforce version constraint. 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. 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.

And, further updates on difference between questions and answers, please visit my blog @