HiddenNetwork.com Banner

Thursday, October 26, 2006

GAC "Access denied" Solution + Free "post-build" Script for Event Handlers

I have been working on an event handler, and I wrote a nice little post-build script to install it everytime I build it:


path = "E:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\"

gacutil.exe /if "$(TargetPath)"

copy "$(ProjectDir)\app.config" "C:\WINDOWS\ASSEMBLY\GAC_MSIL\$(TargetName)\[ASSEMBLY_VERSION]__[ASSEMBLY_PUBLIC_TOKEN]\$(TargetFileName).config"

RecycleAppPools.vbs




  1. Note that you have to replace some things in the code -[ASSEMBLY_VERSION] and ]__[ASSEMBLY_PUBLIC_TOKEN]

  2. Note that I have a configuration file called "app.config" that I am copying into the GAC after deploying the dll.

  3. Also note that I have my "RecycleAppPools.vbs" file in the .net sdk bin folder. This script recycles all application pools automatically, and takes less time than an IISReset.

    To create this file, create a new text file in the bin folder and paste the following code (rename the file to "RecycleAppPools.vbs"):

    Set locator = CreateObject("WbemScripting.SWbemLocator")
    Set Service = locator.connectserver(strServer, "root/MicrosoftIISv2")
    Set APCollection = Service.InstancesOf("IISApplicationPool")
    For Each APInstance In APCollection
    APInstance.Recycle
    Next


All was well and good, but suddenly I began to get errors - the GAC wouldnt let me install the DLL and would tell me 'access denied' when I tried to delete it from the GAC or replace it.

After some internet research I found the solution - stop the indexing service.

Now my little script is running smoothly, and I am developing and debugging my event handler with no problems.

Oh, yeah - I wrote a small application to register the event handler to a list. Anyone interested? I can publish it - it supports both command line operation, and a GUI interface.




4 comments:

r. said...

cool article. it will make my life much easier

Anonymous said...

excellent thanks

Hieu Le Trung said...

Hi,

It's very wonderful, please post the other command :-)

Hieu

Kobi said...

I can't believe stopping the indexing service actually helped.
Thanks!