The GAC, the WebApp, and the _layouts folder

Sometimes I tend to subconciously embark on a dual exploration. Much like trying to kite-surf for the first time, while reading a book of Salman Rushdie in urdu. You'll get there eventually, but the combined tasks will together take a lot more time.

Today I tried to make my Sharepoint site generator work properly while also moving my entire app to the GAC.

First problem was that the webparts no longer was marked as safe. When deploying the assemblies locally you are not required to fully qualify the typename in the DWP file with version and PublicKeyToken. When webparts are in the GAC you have to fully qualify them. So I got punished for avoiding the GAC for a while. The second problem was that the usercontrols couldn't load properly, and I got a lot of nasty CodeDom exceptions.

Because the contents in my WebParts are UserControls, and these are hosted in a separate (excluded) vdir I had to append information about where to find the required assemblies in the GAC in the webapp web.config file. This enabled the ASCX'es to locate the components in the GAC and my webparts were showing again. Also note that in order for the apps to see changes to components in the GAC you have to run IISRESET.

I had verified that the (WSS) site generator worked by switching off FormDigest validation for my top-level website and running the code. Then I wanted to be able to call my Site Generator from an aspx inside the sharepoint _layouts folder, because this folder will have the adequate permissions with validation turned on. I set the buildscript up to create a new folder in TEMPLATE\LAYOUTS called OWLAWYER (i tried Objectware.Lawyer.Sharepoint, the relevant component name, but sharepoint doesn't accept such naming; you'll get file not found). Into this folder I deployed the aspx that contains a FormDigest server control. This aspx receives sitegeneration parameters and calls the sharepoint component in the GAC. I also created a web.config file, similar to the one above, to reference the component in the GAC containing the sitegenerator.

Finally, calling the aspx in the  _layouts/owlawyer folder will only work in the context of a WSS site. Calling it from http://portalroot/_layouts/owlawyer/myfile.aspx causes a security validation error on the FormDigest token. Calling it from http://portalroot/includedpath/wsstoplevelwebsite/_layouts/owlawyer/myfile.aspx works though.

UPDATE: I'd like to elaborate a bit on why I actually wanted to put my components in the GAC after Maxims comment. I agree that in most cases, and especially in development, the GAC causes more problems than advantages. What this post show, however, is that moving to the GAC late in development might cause unexpected problems that should be considered. The main reason I had for deploying to the GAC in this case was that i didn't want to deploy my components in more than one location. With my setup it was required to deploy to A: the web application vdir bin folder B: the sharepoint bin folder (in wwwroot) C: the sharepoint _layouts bin folder. This would truly have caused dll-hell, and especially considering future versioning.

Also check out Maxims post on ipattern to understand why sharepoint behaves this way. I especially liked the sequence diagram.

 

1 Comment

  • I always try to stay away from registering anything into GAC. It requires a lot of restarting of IIS server while developing anything. I like your post, it demostrates to people what are the options for them to run their code.



    Maxim



    [www.ipattern.com do you?]

Comments have been disabled for this content.