Properties in C#

Before talking about Property in C# I want to tell you about other mechanism that can also use in place of Properties- Continue reading


What is Delegate, Multicast Delegate & Event?

Before writing about Delegates I would like to introduce you about the problems that we are facing before delegate come in existence.

Heavy Coupling- Heavy coupling between method declaration and definition creates Continue reading

What is GAC & How to handle multiple versions in GAC?

GAC-Global Assembly Cache is where all shared .NET assembly reside.

GAC is used in the following situations-

1. If the assembly has to be shared among several application which are in the same computer.

2. If the assembly has some special security, requirements like only administrator can remove the assembly. If the assembly is private for program then a simple delete of assembly can delete the assembly file.


Our all share assembly is located in “c:\WINDOWS\assembly\” where we can also see the version and public key token of assembly.


To register any assembly in GAC we have to follow bellow steps-

1. Assign strong name to Assembly

2. Copy the Assembly in another location (like d:\Commondll\) and then register the dll in GAC by 2 ways. First way-

I. Go to Visual studio command prompt

II. Go to d:\Commondll\ (where our Assembly is copied)

III. Just type- gacutil -i common.dll

Second way-

Just drag and drop common.dll file from source to “c:\WINDOWS\assembly\”


Note- We can cross check by search the common.dll in “c:\WINDOWS\assembly\”


Now to use common.dll registered in GAC we have to add reference in windows application from “d:\Commondll\common.dll” and then use common namespace in windows application and now we can use all methods of common.dll in our windows application.

After compilation we will move the windowapplication.exe to “d:\Commondll\” and we can see the .exe running properly because it’s linked with common.dll register in GAC and reside in the same folder.

To create a new version of .dll file in GAC go to Properties->AssemblyInfo.cs in Common class library and update the assembly version- [assembly: Assemblyversion(“”)] and then after build the application lets register this assembly in GAC.

To change the pointing dll by any application-

1. Go to Administrative Tools->Microsoft .NET Framework 2.0 Configuration

2. Right click on Applications in the left hand side tree structure and add windowapplication

3. Select windowapplication after it will add to Applications and click on “Managed Configured Assemblies” then “Configure an Assembly”-> “Choose an assembly from the assembly cache”-> click on “Choose Assembly” and then choose Common which has version and click on Finish.

4. As we click on finish we will get new popup which has Binding Policy tab and enter in Requested Version and in New Version. It creates windowapplication.exe.config file which will redirect the control to new version when it calls for old version.

What is delay signing

Delay Signing helps us to prevent our application from our own developers. Because our developer knows everything about our application, they know strong key file, dll name, function name etc so they can easily take the strong key file and can place a fake dll, that’s where Delay Signing comes into picture.

Structure of Strong Key-

When we create a Strong Key there are 2 parts to it-

  1. Public Key
  2. Private Key

So we have to share only Public Strong Key with the internal developers and when we want to deploy the application at that time we have to add the Private Strong Key and do the deployment.

We can understand the whole concept of Delay Signing by a Strong Key creation-

To create a Strong Key we have to open “Visual Studio Command Prompt”

  1. Go to the desired location where you want to create Strong Name Key file. (for example D:\Akash\Study\Projects\Windows Application\Strong Name)
  2. Type- sn -k MyStrongName.snk. This command created a Strong Name Key file in desired location. This key hold both public as well as private key.
  3. In order to extract Public Strong Name Key from above Strong Name Key file Type-

sn -p MyStrongName.snk MyStrongNamePublic.snk

  1. Now we can give the MyStrongNamePublic.snk file to our internal developers for development and store the MyStrongName.snk file in a secured location and will use this at the time of deployment. REMEMBER A POINT when we using delay signing concept we have to check the check box “Delay sign only” at the time of Public Strong Name Kay file assignment.
  2. At the time of deployment we have to assign the secured Strong Name Key file to the dll so to do this we have to go to the location where the secured Strong Name Key file stored, Type-

sn –R ClassLibrary1.dll MyStrongName.snk