Error adding to GAC
-
Tuesday, June 13, 2006 12:40 PM
Hi,
Only over the last few days I have started getting an error adding a dll to the GAC.
Failure adding assembly to the cache: Access denied. You might not have administrative credentials to perform this task.
Contact your system administrator for assistance.I have admin access to the box. When I get this error, if I open explorer and navigate to the WINDOWS\assembly folder no files are listed.
If I log out and back in the error goes away.
There now I got the error, left it an hour and tried again and it was added fine, and retried adding it and got the error.
Any ideas?
Thanks
Donal
Answers
-
Tuesday, March 11, 2008 5:29 PM
This error is down to the Vista User Access Control (UAC) and whilst turning it off will resolve the issue it may not always be advisable or indeed possible (depending on the security policy).
A better solution than simply turning UAC off is to run the process as a 'Real' administrator or in UAC terms to elevate the process.When UAC is turned on and you log in as an administrator you get given two access tokens as apposed to just one. The first access token is the ‘normal’ access token which has administrator rights and privileges and the second access token is a copy of the first token but with all the administrator stuff stripped out. Thus the second access token is equivalent of an access token granted to a standard user account. It is the second access token that is used by default when executing a process.
In other words when UAC is turned on all processes are run as a standard user by default regardless of whether or not the user is actually and administrator.
To get around this you need to explicitly tell the process to use the first access token and run as an actual administrator.
If you are using a program such as visual studio which needs to access the global assembly cache (GAC) then navigate to the visual studio executable (devenv.exe) in windows explorer and right click on it and select ‘Properties’.
Click on the ‘Compatibility’ tab.
At the bottom of the tab there should be an option called ‘Run this program as an administrator’ make sure it is selected.
Click ‘OK’
If visual studio is already open, close it and re-open it. You should now be prompted by the UAC prompt asking to allow the program to be run as an administrator. Click ‘Allow’.
Visual studio (and all child processes) should now be able to access the GAC.
If you are try to access the GAC via a command prompt (cmd.exe) then the process is slightly different. To do this type ‘cmd.exe’ into the windows ‘Start Search’ and it should then appear in the programs list.
Instead of clicking on it as you would normally do, right click and select ‘Run as administrator’. This open the command prompt with full administrator privileges (and will require an ‘Allow’ on the UAC prompt). You should now be able to gacutil without any problems.
See the following link for more inforation on the UAC:
http://technet2.microsoft.com/WindowsVista/en/library/0d75f774-8514-4c9e-ac08-4c21f5c6c2d91033.mspx?mfr=true- Proposed As Answer by Fact Pandit Saturday, June 07, 2008 6:02 PM
- Marked As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:02 AM
-
Monday, May 12, 2008 3:23 PM
Answering my own question: replacing the call on
%NET%/gacutil /if xyz.dll
by
runas /user:administrator %NET%/gacutil /if xyz.dll
appears to do the trick.
Mike- Proposed As Answer by Richard Harbridge Friday, December 12, 2008 3:12 PM
- Unproposed As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:05 AM
- Marked As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:05 AM
-
Wednesday, January 06, 2010 11:34 AM
I had this issue on Windows 7 and found that running CMD 'as Administrator' solved it.- Marked As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:06 AM
All Replies
-
Tuesday, June 13, 2006 5:13 PM
Hi
[If you close the Indexing Service from Administrative tools then you will not get the Error.]
You can Add an Assembly to GAC When
1. The Assembly should be strong name,
2. You have to Use the Provided utility like GACUTIL.exe to copy DLL into GAC.Thanks
- Unmarked As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:04 AM
-
Wednesday, June 14, 2006 9:24 AM
>>You can Add an Assembly to GAC When
>>1. The Assembly should be strong name,
>>2. You have to Use the Provided utility like GACUTIL.exe to copy DLL into GAC.Not sure if it was clear from my post but it is the same dll I am readding to the GAC after a new build, and sometimes it gets added and sometimes I get the access denied error.
>>[If you close the Indexing Service from Administrative
>> tools then you will not get the Error.]I did not have the Indexing Service UI open but the Indexing service is running alright. Could there be a problem there do you think?
Thanks
Donal
-
Friday, July 07, 2006 10:37 PMModerator
I have the exact issue. My dll is strong named and I'm using gacutil to add it to the gac.
This is blocking me to continue my development. How I can fix/workaround it?
-
Wednesday, July 26, 2006 1:06 PM
Me three (getting this administrative credentials error message on GACUTIL) as are others on my team.
Is there a smoother workaround than logging off/on? It's a real pain to go through that every time this happens.
-
Wednesday, July 26, 2006 1:18 PM
>>Is there a smoother workaround than logging off/on?
besides waiting for an unknown length of time I dont know.
The only thing different about this machine is that I have Office Server 2007 Beta 2 installed. Not sure if that is doing anything in the background that could be causing this.
Thanks
Donal
-
Wednesday, October 11, 2006 12:48 PM
I've heard, that to solve this problem you have to go to "User Accounts" in control panel (Vista) and TURN OFF "User Account Control", but I haven't tried it my self. Hope it works.
-
Wednesday, October 18, 2006 3:38 AMWithout digging a lot into "why", I managed to fix the problem by starting the ".NET Runtime Optimization Service v2.0.50727_X86" service. I hope this helps.
-
Friday, October 27, 2006 2:49 AMthe optimization service didnt work for me, but stoping the indexing service did.
-
Monday, October 30, 2006 4:06 PM
Ishai,
I think you are right and it makes more sense to have an influence from the indexing service than from the optimization one. I must have tried more things and drew the wrong conclusion. I am not sure this is the final answer yet, but it worked for me a couple of times, so whoever is looking for a solution, TRY STOPPING INDEXING SERVICE IF INSTALLING/UPDATING AN ASSEMBLY TO/IN GAC GIVES YOU AN "ACCESS IS DENIED" ERROR AFTER WORKING PROPERLY AT LEAST ONCE, UNDER THE SAME CONDITIONS.
Thanks,
Marian
-
Thursday, July 26, 2007 2:52 AM
Hi guys,
Of course i have the same problem, and...Indexing Service is DISABLED on my machine! Therefore,i guess neither this works! I deploy the assembly to cache using Post-build events via a Install.bat. Every 2nd time it denies me, with the same error adding to GAC. Therefore, i'm forced to rebuild twice!
Did anyone found any solution so far??
C. Marius
-
Monday, October 01, 2007 6:27 PM
I am doing asp.net development and I notice that when I build the gac-ing fails the first time and I'm pretty sure it is because w3wp.exe locks the gac. I run a little process KillAllWorkerProcesses.exe pre-build, and my double-build problem went away -
Wednesday, December 12, 2007 2:40 PM
Hi,
I was having the same problem, for unknown reason DISABLING indexing service resolve the problem... weird !
Thanks
Firas
-
Monday, January 07, 2008 1:57 PM
it never works for me
-
Tuesday, January 08, 2008 12:24 PM
Hi
I had the same issue using post build events to deploy.
What was really wierd was that i had another project that was adding to the GAC successfully.
I restarted the Indexing Service as well as Windows Search service and this resolved the problem.
I found this post on another site:
http://blog.devstone.com/Aaron/archive/2006/02/15/1379.aspx
CACLS %WINDIR%\assembly /e /t /p [DOMAIN|MACHINENAME]\useraccount:R
which explains granting permissions to access the GAC.
Hope this helps.
-
Tuesday, March 11, 2008 5:29 PM
This error is down to the Vista User Access Control (UAC) and whilst turning it off will resolve the issue it may not always be advisable or indeed possible (depending on the security policy).
A better solution than simply turning UAC off is to run the process as a 'Real' administrator or in UAC terms to elevate the process.When UAC is turned on and you log in as an administrator you get given two access tokens as apposed to just one. The first access token is the ‘normal’ access token which has administrator rights and privileges and the second access token is a copy of the first token but with all the administrator stuff stripped out. Thus the second access token is equivalent of an access token granted to a standard user account. It is the second access token that is used by default when executing a process.
In other words when UAC is turned on all processes are run as a standard user by default regardless of whether or not the user is actually and administrator.
To get around this you need to explicitly tell the process to use the first access token and run as an actual administrator.
If you are using a program such as visual studio which needs to access the global assembly cache (GAC) then navigate to the visual studio executable (devenv.exe) in windows explorer and right click on it and select ‘Properties’.
Click on the ‘Compatibility’ tab.
At the bottom of the tab there should be an option called ‘Run this program as an administrator’ make sure it is selected.
Click ‘OK’
If visual studio is already open, close it and re-open it. You should now be prompted by the UAC prompt asking to allow the program to be run as an administrator. Click ‘Allow’.
Visual studio (and all child processes) should now be able to access the GAC.
If you are try to access the GAC via a command prompt (cmd.exe) then the process is slightly different. To do this type ‘cmd.exe’ into the windows ‘Start Search’ and it should then appear in the programs list.
Instead of clicking on it as you would normally do, right click and select ‘Run as administrator’. This open the command prompt with full administrator privileges (and will require an ‘Allow’ on the UAC prompt). You should now be able to gacutil without any problems.
See the following link for more inforation on the UAC:
http://technet2.microsoft.com/WindowsVista/en/library/0d75f774-8514-4c9e-ac08-4c21f5c6c2d91033.mspx?mfr=true- Proposed As Answer by Fact Pandit Saturday, June 07, 2008 6:02 PM
- Marked As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:02 AM
-
Tuesday, April 29, 2008 4:57 PM
It works. I am using Windows Server 2008 64 bit Ver
-
Monday, May 12, 2008 3:03 PMThanks Tom - very useful information for this annoying problem in Vista, for which there seems to me much misinformation around.
Your solution works if I'm interactive. But how do I write a script that executes gacutil? I don't mind the script prompting the user to approve adminstrative access; but I don't want the user to have to right click on cmd.exe and type the command himself!
Mike -
Monday, May 12, 2008 3:23 PM
Answering my own question: replacing the call on
%NET%/gacutil /if xyz.dll
by
runas /user:administrator %NET%/gacutil /if xyz.dll
appears to do the trick.
Mike- Proposed As Answer by Richard Harbridge Friday, December 12, 2008 3:12 PM
- Unproposed As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:05 AM
- Marked As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:05 AM
-
Saturday, June 07, 2008 6:01 PMThanks Tom!!!
You saved my Day :) -
Tuesday, January 27, 2009 3:25 PMFaizel said:
I found this post on another site:
http://blog.devstone.com/Aaron/archive/2006/02/15/1379.aspx
CACLS %WINDIR%\assembly /e /t /p [DOMAIN|MACHINENAME]\useraccount:R
which explains granting permissions to access the GAC.
Thanks Faizel. I am not using VISTA, I'm using XP. I had the same problem for apparently no reason. After seeing your post, I got to thinking that maybe my Domain server was the problem. I develop and test in a VMWare sandbox running a Domain Controller server, another server and a client/development machine. I had opened the firewall to update my Server anti-virus. Because I had forgotten to close the firewall, the development VM could not talk to the DC. Closed the FW and GACUTIL started working again.
Les Potter, Xalnix Corporation, Yet Another C# Blog -
Wednesday, October 14, 2009 2:17 PMSometimes "Access denied" is really "Access denied". :)
I had the same problem when trying to uninstall or add an assembly to GAC with my user. My user was an administrator, but not "administrator".
I tried with "administrator" user and it worked.
I don't know why. -
Wednesday, November 11, 2009 8:49 AM
Answering my own question: replacing the call on
That will ask for the password if the administrator has one right?... hence not very usefull unless the process is manual.
%NET%/gacutil /if xyz.dll
by
runas /user:administrator %NET%/gacutil /if xyz.dll
appears to do the trick.
Mike
Kind Regards
Jens Melgaard
Systems Engenier -
Wednesday, January 06, 2010 11:34 AM
I had this issue on Windows 7 and found that running CMD 'as Administrator' solved it.- Marked As Answer by SamAgainMicrosoft Contingent Staff, Moderator Wednesday, April 21, 2010 6:06 AM
-
Wednesday, March 10, 2010 11:45 AMI had problem registering dll in GAC. "Access denied error".
Just Stop/Restrart "Indexing Service" from Services
Hope it helps,
Thanks,
Ashish -
Tuesday, March 30, 2010 10:01 AM
hey Ashish,
I tried your solution in Windows 7 but it didn't work.
Where should I find indexing Service in Windows 7.
-
Wednesday, July 28, 2010 1:31 PMHi,what is the trick in Windows 2008 r2 ???
-
Friday, January 13, 2012 6:57 PM
- Log on to system as 'the administrator' and not as a member of the local administrators group
- Open a window to the location of the assembly to be registered
- In a new window, now navigate to c:\Windows right click on explore.exe and 'Run as Administrator'
- In the window you just opened as Administrator, navigate to C:\Windows\Assembly
- Now from the first window containing the assembly to be registered, drag and drop the assembly file into the window opened as Administrator
Only approach that worked for me.......

