C# .NET - Diff. between Public and Share Assembly in .Net?

Asked By RAMAKRISHNA T on 11-Dec-11 11:30 PM
What are the Differences between Public and Share Assembly in .Net?
Jitendra Faye replied to RAMAKRISHNA T on 11-Dec-11 11:33 PM
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 Assembly.

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.
Suchit shah replied to RAMAKRISHNA T on 11-Dec-11 11:38 PM

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

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

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 http://www.dotnetuncle.com/difference/47_public_private_assembly.aspx# using the sn.exe tool. This is used to created a cryptographic key pair. http://www.dotnetuncle.com/difference/47_public_private_assembly.aspx# 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 http://www.dotnetuncle.com/difference/47_public_private_assembly.aspx#.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 http://www.dotnetuncle.com/difference/47_public_private_assembly.aspx#. 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.

Suchit shah replied to RAMAKRISHNA T on 11-Dec-11 11:38 PM
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 Assembly.

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

Suchit shah replied to RAMAKRISHNA T on 11-Dec-11 11:39 PM

An assembly in .NET can be classified into two different types' namely public assembly and private assembly. Difference between these two types of assembly is tabulated below:


Public Assembly
Private Assembly
Public assembly can be used by multiple applications. Private assembly can be used by only one application.
Public assembly is stored in GAC (Global Assembly Cache). Private assembly will be stored in the specific application's directory or sub-directory.
Public assembly is also termed as shared assembly. There is no other name for private assembly.
Strong name has to be created for public assembly. Strong name is not required for private assembly.
Public assembly should strictly enforce version constraint. Private assembly doesn't have any version constraint.
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. 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.
Anoop S replied to RAMAKRISHNA T on 11-Dec-11 11:49 PM
Private Assembly
Assemblies are private in scope if only one application can  access them. Private assemblies are only available to  clients in the same directory structure as the assembly. As  a result, the .NET assembly resides in the same directory  structure as the client executable. You can use a private  assembly when it is specific to a client application and no other client application refers to it.

Shared Assembly
When an assembly such as a system assembly contains features shared by various applications, standard
deployment techniques discourage the use of private assemblies. As a result, you need to maintain a copy of the assembly for each client application. You can also register  the assembly in the Global Assembly Cache (GAC), so that  all client applications refer to one copy of the assembly. This type of assembly is called a shared assembly. The side-by-side execution feature of the .NET platform enables you to register multiple versions of the same assembly in GAC.

You can refer my article for more details reguarding how make assembly in .net
http://www.eggheadcafe.com/tutorials/csharp/54797dd2-c4c3-43fb-b67d-b6ee1010ad01/creating-assemly-in-cnet.aspx
DL M replied to RAMAKRISHNA T on 12-Dec-11 12:33 AM
Hi,,,

Get more here

public:->The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private:->The type or member can only be accessed by code in the same class or struct.

protected:->The type or member can only be accessed by code in the same class or struct, or in a derived class.

internal:->The type or member can be accessed by any code in the same assembly, but not from another assembly.

protected internal:->The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.