Archive for category GAC (Global Assembly Cache)

Quick note about some GAC oddities

Ever notice that your GAC dll exists in temp and / or tmp directories in the GAC?  Apparently it’s due to the way the GAC handles installing and uninstalling objects that are locked.  Some more detail here:

http://blogs.msdn.com/junfeng/archive/2006/11/17/gac-temp-and-tmp.aspx

Leave a comment

.Net framework 4.0 – can’t add to global assembly cache

I recently started using Visual Studio 2010 (same thing as the .Net framework ver 4.0).  When I went to put one of my newly created 2010 dlls into the gac I ran into problems. Dragging and dropping to
c:\WINDOWS\assembly
seemed to do nothing, no error, but it never shows up.  I then tried to use
gacutil /i assemblyname.dll
with no luck, it still didn’t show up.

Well, it turns out they moved the GAC (Global assembly cache) for .Net version 4.0.  It is now located here:
C:\WINDOWS\Microsoft.NET\assembly
and it appears to no longer offer the old assembly viewer.  Getting rid of the viewer seems sensible to me, it was full of bugs not the least of which was viewing the gac on a remote machine.  Ever tried?  If you navigate to:
\\someremoteserver\c$\windows\assembly
it will appear to show you the gac on that machine.  Upon closer inspection you’ll find that it’s actually showing you the gac on YOUR machine, NOT the remote machine.

So, good riddance to old rubbish I say.

In order to get a 4.0 framework dll into the gac you will need to run this command: (be sure the latest version of gacutil is in your path for this to work).
gacutil /i YourDllNameHere.dll /f
To verify it worked (and you’ll need to do this because gacutil will return success in many cases, even when it fails) run this:
gacutil /l YourDllNameHere
(Note: gacutil /i requires the full file name but gacutil /l requires the class name, which is normally the same as the file name but omitting the .dll part)

After running gacutil /i if the assembly is 4.0 it will show up here:
C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\YourDllNameHere
and if it’s 3.5 or less it will be here (fyi: you can’t get here with windows explorer, but the folder does exist. You can navigate here using windows command line):
C:\WINDOWS\assembly\gac\YourDllNameHere

EDIT:
Little did I know it when I wrote this short article back in 2009 that it would be so popular! In case you’re still having troubles after reading this I thought I’d elaborate on a couple concepts I assumed most people would know when I wrote the original article. So, if you’re having issues, read on!
Path
I refer to “be sure the latest version of gacutil is in your path” in my original article. If you’re not used to that term it’s an old DOS term that started before windows, back in the 90’s at some point. What the path does is it tells your computer where to look when an app is run. It’s a shortcut of sorts that’s useful if you use the command line. To open a command line go to the start menu, choose ‘run’, type ‘cmd’, press enter.
You should now have a white text on black screen. If you type ‘path’ and press enter you will see the path being used by windows for you at the moment. You can temporarily modify the path by typing:

path="c:\someOtherFolder\";%path%

This will add c:\someOtherFolder to your path list, but only temporarily (for this command line session, once you close the black box it’s forgotten). To permanently change it you have to open:
Control Panel->System->Advanced->Environment Variables->
Here you can choose to either add/modify path for the user (just yourself) or the system (everyone that uses your machine), your choice. Scroll through the two lists, if you don’t see a path variable then it’s not created (blank). You can create it by clicking ‘New’. To edit it just double click and type the new path (this can be tricky as the line is very long, my trick is to copy it to notepad, make the change there, then paste my change back). Remember that the path variable is searched in order, so if gacutil is found in a folder before yours that is the version that will be run.
WARNING:
The path variable is limited in length. If you make it too long windows will truncate it and won’t warn you.
Using the latest version of gacutil
How do you know if the latest version of gacutil is on your machine? Or in your path? Well there are a few steps to this question. First to determine what version is in your path go back to that command window I mentioned in the Path blurb above. Type:
gacutil /version
On my machine I get:
… Version 4.0.30319.1 …
If you get a older version, or file not found, then you’ll need to search your machine for it. Windows search works (but can be slow), I prefer Agent Ransack
Searching my machine for gacutil.exe shows I have all of these versions on my machine: (to get version from a windows search r-click on the file and select “Properties” then the tab “Version”, the version is beside “File version:”)
4.0.30319.1
3.5.30729.1
3.5.21022.8
2.0.50727.42
1.1.4318.0
I believe (it’s worked for me this far) that the latest version is always backwards compatible. So you can just point your path at 4.0.30319.1 and be good. If you don’t have it on your machine you’ll need to download the Microsoft Windows SDK for Windows 7 and .NET Framework 4.
One thing I don’t understand, it appears Microsoft included gacutil in ver 1.1.x of the .Net framework and then never after that. Why MS? Why? The good thing is once you have the SDK you can just xcopy it onto a machine that has the 4.x .Net framework and it will run. I’ve done that for some automated deployments I’ve done.

2 Comments