Inside Regsvcs.exe

Just out of curiosity, I decided to sniff around and see how Regscvs.exe does it's work to register an assembly in a COM+ application. While this information is probably not very useful to anyone, I'm posting here a few interesting snippets of what I found:
  • Regsvcs is just a driver around the System.EnterpriseServices.RegistrationHelper class. This class is esentially a wrapper that ensures that all registration is done from a thread in an appropriate apartment, while the actual registration work is done inside the RegistrationDriver class (the entry point to this class is the InstallAssembly() method).
  • First thing It does is create a TLB if it's needed, which is done through the RegistrationDriver::GenerateTypeLibrary() method, which is, of course, done through the TypeLibConverter class in the System.Runtime.InteropServices namespace.
  • All Custom attributes implemented in System.EnterpriseServices for COM+ registration have private implementations of the System.EnterpriseServices.IConfigurationAttribute interface. All the basic catalog registration is driven through this interface. In essence, a great deal of the work of the RegistrationDriver is simply to iterate through collections of types to extract this attributes and call the IConfigurationAttribute methods on them at the appropriate time.
  • The interface has the following declaration:
    
    interface IConfigurationAttribute
    {
    bool IsValidTarget(string s);
    bool Apply(Hashtable info);
    bool AfterSaveChanges(Hashtable info);
    }
    
  • The first method called is IsValidTarget(), which should return true if the registration attribute can deal with the specified kind of object, which is identified in COM+ terms with a string. So for example, here are some possible values:
    • "Application": The object representing the COM+ application object being created.
    • "Component": The object representing the COM+ component being registered.
    • "Method": The method of the component/interface being processed.
  • Both of the other two methods of IConfigurationAttribute interface take a Hashtable as an argument, in which keys are strings, and values are instances of types that implement the ICatalogObject interface. As you've probably guessed by now, common keys in the Hashtable are the three strings presented above ("Application", "Component", "Method").
  • The Apply() method is where most of the work actually occurs. Most attribute classes simply get the appropriate ICatalogObject instance out of the Hashtable and call SetValue() on it to configure a particular property in the COM+ Catalog, so it's actually quite straightforward.
  • The AfterSaveChanges() method is, from what I can tell, basically a way to provide for two-step registrations. Most attibutes simply don't do anything in this method (In fact, I couldn't find any attribute that actually takes advantage of this method in v1.0 of the framework.).

Keep in mind, of course, that all of this stuff is completely undocumented, and very likely to change in future versions of the framework...

1 comment

  1. Hi Tomas,

    I am really stuck with an issue here and was hoping you might be able to comment. I am trying to deploy a .NET assembly using the System.EnterpriseServices.RegistrationHelper class, but get the following error:

    System.EnterpriseServices.RegistrationException: Could not install type library ‘c:\vss\orange\binaries\Orange.Framework.Configuration.tlb’ into application ’20twenty’.

    Server stack trace:

    at System.EnterpriseServices.RegistrationDriver.InstallTypeLibrary_W2K(ApplicationSpec spec)

    at System.EnterpriseServices.RegistrationDriver.InstallTypeLibrary(ApplicationSpec spec)

    at System.EnterpriseServices.RegistrationDriver.InstallAssembly(RegistrationConfig regConfig, Object obSync)

    at System.EnterpriseServices.RegistrationHelperTx.InstallAssemblyFromConfig(RegistrationConfig& regConfig, Object sync)

    at System.Runtime.Remoting.Messaging.Message.Dispatch(Object target, Boolean fExecuteInContext)

    at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

    Exception rethrown at [0]:

    at System.EnterpriseServices.RegistrationThreadWrapper.PropInstallResult()

    at System.EnterpriseServices.RegistrationHelper.InstallAssemblyFromConfig(RegistrationConfig& regConfig)

    at System.EnterpriseServices.RegistrationHelper.InstallAssembly(String assembly, String& application, String partition, String& tlb, InstallationFlags installFlags)

    at System.EnterpriseServices.RegistrationHelper.InstallAssembly(String assembly, String& application, String& tlb, InstallationFlags installFlags)

    at InstallStuff.Form1.InstallCOMStuff() in C:\Poes-Pas\InstallStuff\Form1.vb:line 277

    The exact same component registers fine through regsvcs.

    The line of code that I use to attempt the registration is as follows:
    RegistrationHelper.InstallAssembly(AssemblyName, ExistingApplicationName, TlbName, EnterpriseServices.InstallationFlags.Default)
    AssemblyName = Full path & filename of DLL,
    ExistingApplicationName = “20twenty” – this application exists
    TlbName = Nothing

    I’ve been battling with this issue for hours now L

    Literally any comments will be much appreciated,
    Regards,
    Kenny

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>