Deploying the Assembly Cerberus’s Final Head
Here we are on the verge of success and we take another mighty hit from Cerberus. To overcome this hit we have to ask, which method of installing assemblies into the Global Assembly Cache (GAC) is correct? There are a plethora of articles on this topic. Some simply say drag n’ drop the DLL into the GAC folder, others tell you to use PowerShell, most say use Windows Installer or gacutil.exe. As you might expect, some of these are outdated unless you are running a version of Windows that hasn’t been popular since Britney Spears had her meltdown (most likely caused by an unintentional upgrade to Vista). Digression aside, I opted for the quick and dirty solution and used the Gacutil; however, licensing prohibits packaging the Gacutil with your project so your only choice, if distributing the code, is to create an InstallShield Installer.
Key things to remember here are any DLL’s your assembly depends on must be registered in the GAC as well before your code will work. Remember what I said in bold from Part 2? Make sure the .NET Framework versions match up as well. I was so battle-weary from everything leading up to this that I missed that little detail and wasted several hours because of it. You’ve been waiting a long time though, six pages in fact, and here are the last strikes needed to complete your labor:
gacutil /i <path to DLL> /f
BOOM! One final definitive blow and you have completed your Herculean Labor. If you have any third party assemblies, go ahead and register them now using the same command. If you want to be sure everything has been installed correctly, you can dump out the contents of the GAC using:
gacutil /l > C:\gacDump.txt
I recommend dumping it to a .txt file as shown below since there can be a lot of assemblies in the GAC and it’s super helpful to do a search for the DLL name rather than a line by line needle in the haystack search.
One final step will solidify your place amongst the Greek heroes: document the work so the next sorry sap doesn’t have to do what I did. That is what I consider my long journey back out of DLL hell. The problem was solved! I was victorious, but I needed to reflect on what I had done that worked and what paths I strolled down that were wrong. This post, verbose as it may be, is considerably shorter than if I had included everything I tried and read before truly understanding the problem. I have included the most helpful resources I used below and recommend all of them if you are new to writing Global Assemblies like I was.
I found the following tutorials and topics extremely helpful and I strongly suggest reading through them if you are not familiar with working with assemblies of the GAC. I especially recommend the .NET-fu post.
.NET-fu – At the very least, you will want to read this as it details how to strongly name third party assemblies that were compiled without being strongly named. For our purposes — the Foo, Bar, Baz section is extremely helpful.
Ian Picknell’s Blog – Helps to understand what Microsoft tools are used for and how to use them while working with third party assemblies.
CodeProject.com 4352 – Good overview of the .NET GAC. Article is a little outdated as far as the tools go though.
KB925568 – Details how to verify the version of .NET Framework you have installed. Good news! A month prior, I had just upgraded the code to use the latest and greatest .NET Framework. Bad News! The server was so outdated the latest .NET framework was incompatible.