Sunday, February 20, 2011

Difference between Private, Public and Satellite assembly

An assembly is the basic building block in .NET. It is the compiled format of a class, that
contains Metadata, Manisfest & Intermediate Language code.
An assembly may be either Public or Private. A public assembly means the same as Shared

Private Assembly - This type of assembly is used by a single application. It is stored in the
application's directory or the applications sub-directory. There is no version constraint in a
private assembly.

Shared Assembly or Public Assembly - A shared assembly has version constraint. It is stored
in the Global Assembly Cache (GAC). GAC is a repository of shared assemblies maintained by
the .NET runtime. It is located at C:\Windows\Assembly OR C:\Winnt\Assembly. The shared
assemblies may be used by many applications. To make an assembly a shared assembly, it has
to be strongly named. In order to share an assembly with many applications, it must have a
strong name.

A Strong Name assembly is an assembly that has its own identity, through its version and

In order to convert a private assembly to a shared assembly, i.e. to create a strongly named
assembly, follow the steps below...

1) Create a strong key using the sn.exe tool. This is used to created a cryptographic key pair.
The key pair that is generated by the Strong Name tool can be kept in a file or we can store it
our your local machine's Crytographic Service Provider (CSP). For this, goto the .NET
command interpreter, and type the following...

sn -k C:\samplekey.snk

This will create a strong key and save it to the location C:\samplekey.snk 2) If the key is
stored in a file, just like we have done above, we use the attribute AssemblyKeyFileAttribute.
This belongs to the namespace System.Reflection.AssemblyKeyFileAttribute. If the key was
in the CSP, we would make use of System.Reflection.AssemblyKeyNameAttribute.

Go to the assemblyinfo.vb file of your project. Open this file. Make the following changes in
this file...

<assembly: assemblykeyfileattribute("C:\samplekey.snk")>

We may write this in our code as well, like this...

Imports System.Reflection
<assembly: assemblykeyfileattribute("C:\samplekey.snk")>
Namespace StrongName
Public class Sample
End Class
End Namespace

3) Build your project. Your assembly is now strongly named.
Installing the Shared assembly in GAC...
Go to .NET command interpreter, use the tool gacutil.exe
Type the following...
gacutil /i sampleclass.dll
To uninstall it, use... gacutil /u sampleclass.dll. Visual Studio.NET provides a GUI tool for
viewing all shared assemblies in the GAC.

A Satellite Assembly - is an assembly that contains only resources, and no code. The
resources are location specific. A satellite assembly is associated with a main assembly,
the one that actually contains the code.
In .Net Framework,  .Net  Assembly can be classified in four Categories:

(A) With Respect to Program Access.
i) Private Assembly- It can be used only in one application.
ii) Public/Shared Assembly- It can be used by all applications in the server.

(B) With Respect to Number of Resources.
i) Static Assembly- It uses fixed resources.
ii) Dynamic Assembly- It supports dynamic creation of resouces or files at
runtime programatically.

(C) With Respect to Deployment.
i) Satellite Assembly- Easily Deployable. (Visual Studio 2005).
ii) Resource-Only Assembly- In Visual Studio 2003.

(D) With Respect to Number of Assemblies.
i) Single File Assembly- /Bin/x.dll

ii) Multi File Assembly- /Bin/x.dll

No comments :

Post a Comment