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 a collection of information to execute an
application.
Types of Assembly
- Private assembly (.dll and .exe are at the same place)
- Shared assembly
(.dll and .exe are at different place)
-
Dynamic assembly (dynamically create )
- Distributed assembly (in different parts)
- Satellite assembly (on the 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 the same folder & the main file can't directly 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 a 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 is known as a strong name key. It is a string that is a large collection of alphabet and numeric values, 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
This will create a key having the name shrd.snk(128-bit key ).
Note: To generate the key it uses RSA2 (Rivest
Shamir Alderman) algorithm.
Step 3: Apply the key on our class file by written the code in .dll
source 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
Step 5: Now
register/install .dll into GAC. GAC is the database of CLR in the case of .NET. After
installing this .dll in GAC, any file can use it with the help of CLR.
Step 6: The Client Application is 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