Thursday, May 29, 2003 10:55 AM
Shawn A. Van Ness
In defense of regasm /codebase
It seems to me that regasm /codebase gets a bad rap. I guess that's to be expected -- it's a pretty self-deprecating little command line switch. This is what it has to say for itself, when run against an unsigned assembly:
RegAsm warning: Registering an unsigned assembly with /codebase can cause
your assembly to interfere with other applications that may be installed on the
same computer. The /codebase switch is intended to be used only with signed
assemblies. Please give your assembly a strong name and re-register it.
Adam Nathan also has some harsh things to say about regasm /codebase in his excellent COM Interop book... and lately some colleages of mine, both here and abroad, have been on my case about this, for some reason. (The guys who make our setups say that InstallShield just totally refuses to register an unsigned assembly for COM Interop.)
Maybe I just don't see what the problem is... I did the COM development thing for the better part of a decade, and none of my DLLs were ever signed with a strongname. In COM, we had GUIDs for strongnames. Well with COM Interop, we still have GUIDs! COM Interop is still COM.
Fundamentally, regasm /codebase is no different than regsvr32: they both register a path to a DLL under HKCR/CLSID/{some big number}/InprocServer32. The fact that regasm squeezes a virtual class factory in there -- forwarding to Assembly.LoadFrom from mscoree.dll!DllGetClassObject -- is an implementation detail.
The only good argument I can think of against regasm /codebase (one which I haven't seen mentioned anywhere) is perf. The codebase value in the registry is apparently the very last place the CLR looks, when loading a type for COM Interop (after the GAC, and after probing the apppath, etc -- note that these semantics differ from that of the <codebase> element in an app config file, which override probing).
But hey, no strongname means no signature to verify, thus saving a few cycles on that side of the equation. ;-) And CoCreateInstance is already such a big bloody monster, I doubt that the perf difference between GAC and codebase would be noticable to an end-user -- one certainly wouldn't want to call CoCreateInstance in a very tight loop, even in the best of circumstances!
So, what's the deal, folks? Let regasm /codebase live!