Friday, February 11, 2011

Access Denied message when dropping a file into the GAC (or it doesn't work)

I was using Windows Server 2008 R2 and trying to add a file to the GAC. As you know the easiest way to do this is to drag and drop the file from one window into a window with the location C:\windows\assembly.

I kept getting the Access Denied error message. I tried running the command prompt as the Administrator, navigating to C:\Windows\assembly and then typing "Start . " to open an explorer window as the Administrator. Repeated the file drop but got Access Denied again.  At the time this was a .NET 3.5 assembly.  Now with .NET 4.0 the location of the GAC is no longer C:\Windows\assembly but C:\Windows\Microsoft.Net\assembly and drag and drop is disabled.

OK, so  the other way to install it is to use GACUTIL but guess what, its not installed on the production server. And no you can't use an old version of GACUTIL from .Net Framework 1.1, it has to be the .NET version that your DLL is using. Google said it was in the Microsoft SDK for Windows but I didn't have time to download it.

I managed to copy it from a Hyper-V image I had which had Visual Studio 2010 installed. The file for .Net v3.5 is located in C:\Program Files (x86) \Microsoft SDKs\Windows\v7.0A\bin. You just need to copy GACUTIL.EXE and GACUTIL.EXE.CONFIG.

For .Net 4.0 the location is C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools and you need a third file 1033\gacutlrc.dll for gacutil to work.  When you copy this to the production server all 3 files can be in the same directory. 

The syntax is
gacutil /i myassemblyname.dll /f

To check the file is in the GAC use
gacutil /l myassemblyname           (don't add the .dll)

Hope this gets you out of the same hole I was in.

1 comment:


Great article/technical notes. Works charm. Thank you very much for this info..