SIGN UP MEMBER LOGIN:    
ARTICLE

Concept of Shared Assembly in .NET

Posted by Deepak Dwij Articles | C# Assemblies October 22, 2011
This article describe the concept of shared assembly with Reflection in .NET.
Reader Level:
Download Files:
 

Introduction:

Assembly

Assembly is the smallest unit of deployment, it is the collection of various things to perform a common task or goal. It is also called the logical entity that is collection of information to execute an application.

Types of Assembly

  1. Private  assembly (.dll and .exe  are  at same place)
  2. Shared assembly (.dll and .exe  are at different place)
  3. Dynamic assembly (dynamically create )
  4. Distributed assembly (in different parts)
  5. Satellite assembly (on network)

Shared Assembly

For using a shared assembly an application must have a key (token) for authorization and authority.

When .dll and main file are not in same folder & main file can't direct access the .dll file. It must take permission for Runtime manager for using that .dll, then the collection to run the file can be known as shared assembly.

Steps to create Shared assembly

Step 1: Create a class file
 
using System;
namespace SharedAssembly
{
    public class Bike
    {
        public void start()
        {
            Console.WriteLine("kick start ");
        }
   }
}


Step 2: Generate the token

This token known as strong name key. It is the string that is large collection of alphabet and numeric value, it is very big-string. It is also so long so that no one can access without any permission.

--> open command prompt of visual studio

             D:\shared assembly> sn -k shrd.snk 

keygeneration.gif 

This will create a key having name shrd.snk(128 bit key ).

Note: To generate the key it use RSA2 (Rivest Shamir Alderman) algorithm.

 
Step 3: Apply the key on our class file by written the code in .dll source file

 
// add this code to your class file
using System.Reflection;
[assembly:AssemblyKeyFile("shrd.snk")]

Class file

using System;
using System.Reflection;
[assembly:AssemblyKeyFile("shrd.snk")]
namespace SharedAssembly
{
    public class Bike
    {
        public void start()
        {
            Console.WriteLine("kick start ");
        }
   }
}

Step 4: Complied the code file & Create a .dll file of Bike class

dll-creation.gif

Step 5: Now register/install .dll into GAC. GAC is the database of CLR in case of .NET.After installing this .dll in GAC, any file can use it with the help of CLR.

To install

D:\shared assembly>gacutil /i sharedAss.dll

gac-utill.gif 

Step 6: The Client Application are as follow 

using System;
using SharedAssembly;
public class MainP
{
    public static void Main(string []args)
    {
     Bike bk=new Bike();
     bk.start();
     Console.Read();
   }
}

Step 7: Compiled the whole application

 D:\> csc /r:d:\shared assembly\sharedAss.dll MainP.cs

Step 8: Run your program by using the command given below:

D:\>MainP

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Become a Sponsor