Friday, September 29, 2006

Assemblies in GAC under Debugger

I did say at the beginning that this Blog is reserved for my whining about Microsoft products. Wow, after a while it seems positively negative.
However, whenever I run across something that tightens up those old jaw muscles, this is the first place I think of to put it.

So here's the latest thing I've stubbed my wrastler's toe on. Putting my artwork (id est, programs) in the GAC. The GAC is the Global Assembly Cache, and you can find it in this directory:

%SystemRoot%\assembly

Well, that's not really a directory. It's a just a name in the shell namespace that maps to the GAC. Anyway, let's just say you can put your priceless .NET libraries in this global place, and any program you want can use it.

The problem comes when it is time to debug some happy little program that happens to use your GAC assembly. Here's the scenario.

Say you have a library called Lib. You compile it and put it in the GAC. This library defines an interface, say IBlob, that defines a method, say Func.

Now, suppose you write a client of Lib, say User. Then User must supply an object to Lib that implements IBlob. Call it Client. So Client has gotta implement Func. And now further suppose that Client's implementation of Func throws an exception.

Well, now, Lib has been carefully crafted to handle any exception thrown in the Func method in some generally acceptable manner. But when you run User under the debugger, and Func throws its exception, you do not get the acceptable handling that Lib provides. Instead you get a debugger message that says, "Exception was unhandled by user code."

If you run User naked, Lib kicks in and handles the exception as it should, giving you all the benefits of your amazing implementation. But under the debugger, you get a flagging break in your program when you actually expect this exception to happen occasionally and depend on Lib to handle it gracefully. So how do you debug your program? You have to make sure the debug version targets a version of Lib that is not in the GAC. What. A. Royal. F. Pain!

Of course, as I've probably already said in all my disclaimers, there is probably a very elegant way to handle this, but the documentation fails to mention it. Or makes it hard to find. Or, blah, blah, blah.

0 Comments:

Post a Comment

<< Home