views:

61

answers:

2

Hi Folks,

This one goes round and round I know but I can't seem to find a satisfactory response.

Should assemblies go in the GAC? These questions: when-and-when-not-to-install-into-the-gac and What are the advantages and disadvantages of using the GAC, address exactly that but the answers are very much "it is recommended that..." or "you should only ...". Why???

A lot of the GAC naysaying blogs seem to date from 5/6 years ago when .Net's star was beginning it's rise. Are we still there now? Surely DLL-Hell is a thing of the past with the GAC supporting side by side installation of different versions of the "same" assembly?

Let me flesh-out my concerns. We have a growing suite of web apps (5 so far). These are, at their core, extensions to a third-party application via API calls and database extensions. Obviously, therefore, all these apps share a great deal of code in common and we are developing a new set of core shared libraries to improve our quality, maintainability, etc.

Surely I want this shared functionality installed once and shared. All the arguments about opening a maintenance nightmare seem based on some world of poor discipline. If you break the ABI then bumping the AssemblyVersion is sufficient to keep your existing apps working.

Is the GAC truly a honey trap for the unsuspecting? Am I being naive? Am I being unnecessarily harsh when I dismiss arguments citing the loss of 'XCopy' install as being lazy whinges? Or is it getting a bit "Religious" and I should just go with what seems right?

Thanks for helping me see the light.

Dan

A: 

I use following weak strategy.
Use GAC - when different programs use shared assembly + versioning.
Don't use GAC - always.

any comments are welcome.

Sergey Mirvoda
+2  A: 

I personally have never installed any assemblies directly in the GAC (except as a purely academic exercise). I've heard the argument before about using an assembly from a centralized location that is accessed from several applications, and while that seems somewhat attractive, personally, it's not worth my time. Computers come with 320GB of hard disk space these days... my measly 160K assembly isn't going to make a dent in that, even if it's copied 5 times. (Of course, some could argue the "problem of the commons"... you know: "if every developer thought that way....", but I digress). The main reason I choose not to do this is because one particular application might rely on the assembly in one way, while another might rely on it another way. While in an ideal world, updates to this assembly should never affect the applications that rely on it, in reality, it often does. If I'm fixing a problem with an assembly because a particular application has issues with it, I'm unwittingly affecting the other applications that rely on that particular assembly. On the other hand, some might argue that this kind of situation makes us better programmers and makes our GAC-Shared assembly more bulletproof. That's great, but my job as a programmer isn't primarily to make myself a better programmer, but to write programs that work, and doing so, I will become a better programmer.

So what's my vote? Keep away from the GAC. Let each application rely on the version of the assembly they're built to rely on. A bug exposed in that assembly by one application may never show up in the other applications, because they're using the assembly differently, so leave them be and you won't have to regression test 5 distinct applications every time your shared DLL gets patched.

David Morton
Yeah, disk space not really my concern :) I appreciate the honesty of your answer but I have to argue that if two consumers of shared code exhibit different but correct behaviour then there's a question mark about the separation of the functionality. I think I see things the other way round - if I make myself a better programmer then, QED, I write better programs.
Dan Kendall
I'd say there's definitely a balance, however. Yes, you want to become a better programmer, and becoming a better programmer helps you to write better programs, but there are better ways to become a better programmer than by pressure-cooking assemblies in production.
David Morton
I'm not sure I understand your "pressure-cooking" term. I agree entirely with the need for a balanced and pragmatic approach. The issue is that it seems your and others' responses to the GAC question could be paraphrased (and I merely do this to hilight my concern - not to belittle your opinion) as "we think the GAC is a good idea but we want to avoid the overhead of making our code work happily with it." Which is a rather jaundiced view of development to present in such blanket responses. I'd rather know the specific risks and make my own mind up. Please correct me if I'm wrong.
Dan Kendall
No, I'm with you completely. The main risk I see here is something I mentioned in my original post. If you do have to change something in a GAC-installed assembly, you'll by necessity, need to regression test every application that utilizes that particular assembly. This can get nasty. Sure, I suppose that having several versions of the assembly can also get nasty, but for the most part, my apps, once deployed, pretty much sit there. I'd rather fix the bug for one app, and leave the working ones alone, than risk introducing a new bug while trying to solve another.
David Morton
Thanks for your patience David. And thank you for your answers. I understand and agree completely. The problem we need to solve, then, is automated and reliable regression testing. I guess this should be a new question "Do we think gated check-ins + automated builds + unit tests are able to provide this layer?" I feel relieved that there wasn't some lurking nasty that everyone but me could see :)
Dan Kendall