Types Of Assemblies, Create Private Assembly in C#.Net

 

An Assembly is a compiled code library that used for versioning, deployment and security. There are two types of assemblies available in .Net. Those are Process Assemblies and Library Assemblies. Process Assemblies has extension of .exe and Library Assemblies has extension of .dll.

 

There are three different types of Assemblies available in C#.Net.  Those are Private Assemblies, Public Assemblies(also called Shared Assemblies) and Satellite Assemblies.

 

In this article we discuss about what private assembly is, how to create private assemblies and what are advantages of private assemblies.

 

Private assemblies are required to locate within the client application folder. That means if you want to use any private assembly in your application you have to maintain separate copy of that assembly in your application. We discuss private assemblies in .Net through simple example.

 

Create assembly in .Net by opening Visual studio Framework=>Create Project=>Select Class Library=>give name as “PrivateAssembly” and add below code.

 

namespace PrivateAssembly

{

    public class Class1

    {

        public string display()

        {

            return "This is from Private Assembly";

        }

    }

}

 

Build this application. If you build this application in Debug mode you will find PrivateAssembly.dll in Debug folder of bin folder or if you build this application in release mode you will find the PrivateAssembly.dll in release folder of bin folder.

 

Now we have to create Client Application to use above created private assembly. For that by open Visual studio Framework=>Create Project=>Select Console Application and give name as ReferPrivateAssembly.

 

Add PrivateAssembly.dll by right click on solution explorer and select Add reference, add PrivateAssembly.dll file. Then you will find this PrivateAssembly.dll file in your client application folder bin directory. Add below code to call assembly methods.

 

namespace ReferPrivateAssembly

{

    class Program

    {

        static void Main(string[] args)

        {

            PrivateAssembly.Class1 obj = new PrivateAssembly.Class1();

            Console.WriteLine(obj.display());

            Console.ReadLine();

        }

    }

}

 

The output display as shown below by calling PrivateAssembly display() method.

 

                                                                                                           PrivateAssembly.zip (11.74 kb)

                                                                                                   ReferPrivateAssembly.zip (25.16 kb)