Locked History Actions

MyBlog/BlogEntry-2007-06-30

.NET COM Component Registration Woes

I recently wrote some COM components in C#/.NET. These happened to be pipeline components for a Microsoft Commerce Server 2007 implementation, but they are COM components none the less. During development the components were registered on our local development PC and on our shared development/integration server by the Visual Studio IDE so I didn't think much about the process of registering these components. However when we deployed to the QA environment this had to be done "by hand". The RegAsm utility that comes with the .NET runtime is used to register .NET COM components so I registered them like this:

  • C:>regasm mypipelinecomponent.dll

RegAsm then prompted me with a dialog that the component had registered.

When we went on to test the deployment, I quickly learned that our Commerce Site's ASP.NET application did not run correctly because the pipeline components were not registered properly. Comparing the registry entries on the QA and DEV environment revealed differences.

It turns out that when you register .NET COM components that RegAsm assumes that you have placed your COM component assembly file(s) in the GAC (Global Assembly Cache) and does not add the "CodeBase" entry in the registry which would normally contain the path to your assembly. This results in the run-time not able to find your assembly.

The fix for this is to add the "/codebase" switch when you register your component like so:

c:>regasm mypipelinecomponent.dll /codebase .\mypipelinecomponent.dll

Note that you do not have to give the full path to the component. Using this switch will cause RegAsm to add the codebase entry in the registry.

After learning this the hard way I kicked myself after running across specific instructions in the Commerce Server Documentation on how to deploy pipeline components, but the this registration process should be utilized whenever you are going to implement COM components and try to access them from any COM Client.