COM+ registration and permission errors

If you are using EnterpriseServices (COM+) from a web application you need to make sure that you manually register your components with COM+ when deploying your app. 

If you don't register your services with COM+ then, when you run your application for the first time and attempt to run code which uses EnterpriseServices, the asp worker process will attempt to auto-register your COM+ application.  This registration requires administration privellages - which, obviously you wouldn't want your asp process to have.  In this instance, asp will throw an exception stating that the Class "X" cannot be found as a COM+ application and you will see the following message displayed:


Server Error in '/ComPlusTests' Application.

Access to the registry key HKEY_CLASSES_ROOT\ComPlusLibraries.Worlds is denied.


The answer is to use Regsvcs.exe to register your component.  There's an excellent article which describes the entire this stuff in amazing detail titled: Understanding Enterprise Services (COM+) in .NET

Here is an excerpt from that article which describes what goes on under the hood when you run Regsvcs:


Conceptually, RegistrationHelper performs the following steps:

  • Uses RegistrationServices.RegisterAssembly to register the assembly in the registry. Therefore, classes appear in the registry as COM components written in managed code and have the InprocServer32 key pointing to mscoree.dll. If a managed class does not implement any interfaces, the class's public methods do not appear in the COM+ catalog, unless the ClassInterfaceAttribute is used. This means that service configuration associated with the method level cannot be stored in the catalog. However, some COM+ services can be configured at the method level and require the component to expose an interface as viewed in the COM+ catalog. For example, COM+ role-based security on the method level requires a component to implement an interface in order to configure the service. More is discussed about this issue in the security section.
  • Generates a COM type library from the assembly using TypeLibConverter. ConvertAssemblyToTypeLib.
  • Registers the type library. So far, this is very much the same as RegAsm.exe /tlb.
  • Finds or creates a COM+ application. The name is extracted from the ApplicationName attribute, the assembly name or the supplied application name/GUID.
  • Uses the type library to configure the COM+ application using the COM+ admin APIs.
  • Goes through all the custom attributes and uses IConfigurationAttribute to write configuration data for the particular service to the COM+ catalog.

No Comments