Place .NET DLL in GAC

Today other team guy has asked me help as he was facing some problem in trying to place a .NET DLL in GAC where he does not have source code with him.

Potentially you just have to follow regular steps as mentioned below to place the DLL in GAC;

1. Generating the public key:
Go to visualStudio.Net command prompt and type the following command:

sn -k keyfile1.snk
Here keyfile1.snk is the keyfile we are generating.

You can store this key file in the bin folder of the assembly. In order to do this u have to go to the bin folder.
For example:
C:\foldername\assemblyname\bin sn-k keyfile1.snk

By doing this the keyfile is stored in the bin folder.

2. Than place the keyfile into the Assembly.
Go to AssemblyInfo.cs file:
[assembly: AssemblyKeyFile("C:\foldername\assemblyname\keyfile1.snk")]

3. Then build the Assembly.

4. Placing the assembly into GAC

This process is fine when you have source code with you.

What if you don't have the source code with you and you need to put it to the GAC. Here you will not be able to follow the 2 and 3rd step.

Therefore, we need this little tip to be able to sign a DLL without a source code.
These are the steps that you have to follow to sign the DLL;

1. You will need to use .NET SDK to create a new key. you can do this by either within the Visual Studio IDE or using the command prompt by typing “sn -k keyfile1.snk“. Be sure to record the path where you keep this key.

2. Using the command prompt, go to the folder with your DLL. Copy ilasm.exe and ildasm.exe to the same directory and also the previously created key file. (In this case example.snk)
Note: if you have your environment variables set up to .NET SDK then you don’t have to copy these programs or you can reference the path explicitly.

3. Type ildasm assemblyname.dll /out=assemblyname.il to decompile the DLL into IL format with the resource file that we will use later to be attached with the key file

4. Type ilasm assemblyname.il /dll/resource=assemblyname.res /key=assemblyname.snk /optimize. This command recompiles the DLL with the il file, resource file and the new key file together.

5. Validate the strong name by using “sn -v assemblyname.dll” from the command prompt.

You now have a strongly typed DLL that can be safely signed in any application without source code or recreating a build environment.

Finally, still I have a problem of pace this DLL in GAC by calling Gacutil.exe
I will have to spend some more time to fix this.

Comments

Unknown said…

I read your articles very excellent and the i agree our all points because all is very good information provided this through in the post. It is very helpful for me. Keep blogging like this. Thanks.


SAP training in Chennai
Aashi siva said…
This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.Your final conclusion was good. We are sowing seeds and need to be patiently wait till it blossoms.

Corporate Training in Chennai

Sowmiya said…

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.



Online Reputation Management
Unknown said…
Thank you for sharing like this information. This is the most easy way of learning. This helps me to get some idea regarding this and helps me to bring a creative thought.
Digital Marketing Company in Chennai
Unknown said…
Really i enjoyed very much. And this may helpful for lot of peoples. So you are provided such a nice and great article within this.


Best Dental Clinic In Tambaram
sathya said…
There are lots of information about latest technology and how to get trained in them, like this have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies. By the way you are running a great blog. Thanks for sharing this.

MSBI Training in Chennai

Informatica Training in Chennai
Nandhini said…
Great post! I am see the programming coding and step by step execute the outputs.I am gather this coding more information. It's helpful for me my friend. Also great blog here with all of the valuable information you have.
Facility Management Companies in Chennai

Popular posts from this blog

Interview Questions to Ask the Employer

Windows Communication Foundation - FAQ