Monday, September 24, 2007

Getting your COM objects to run on a shared web server

It turns out to be possible to run COM objects without registering them with regsvr32 or COM+ thingy. Furthermore, this is how we operate our online demos here :-) (of course, we plan moving to a dedicated one ASAP 'cause some are real heavy, especially DeepAnalyzer). Clarion developers: these are pure Clarion COMs.


The secret is to use so-caled side-by-side execution (SxS) which has been around since Windows 2000 (or XP) in ASP.NET environment (yet another reason to migrate to ASP.NET). ASP.NET 1.1 had this activation model as a default; ASP.NET 2.0 had it removed, but there is a workaround: a free (for now!) 3rd party library by MazeComputer taking advantage of ASP.NET "HTTP modules".


A few gotchas:


  • If you have a separate TLB (not linked inside the DLL), don't rely on MS Studio manifests. Build them yourself. Attached is an example of a working manifest.

  • Do not use AspCompat=true directive on that page. Even though it is recommended with COM objects, AspManifests does not work with it. Their support told me it's because the "performance boosters" create disarray between threads (in fact, AspCompat is supposed to limit everything to just one thread (IIRC) - strange).

  • Probably because of some kind of threading issue with the same library, you need not only to release the memory (myObj = Nothing), but also call the garbage collector to collect the garbage (GC.Collect()) after each disposal. Otherwise, you might get crashes here and there.
All the rest works like a Swiss chronometer. Feel free to ask questions if anything is not clear.

No comments: