July 5, 2005 tools

Register for COM Interop and VS05b2

I was helping a colleague work through a .NET COM interop issue. He’d found my article on the topic (“Hosting Windows Forms Controls in COM Control Containers), but couldn’t get it to work. He’d set the Register for COM Interop setting and adding the Guid attribute to his .NET type, but nothing was registered at build-time.

The problem was that, unlike VS03, the wizard-generated AssemblyInfo.cs has the assembly-wide ComVisible attribute set to false” which causes regasm (the command-line version of what VS is doing to register your .NET assembly with COM at build-time) to skip the registration of all of the .NET types in your assembly, defeating the purpose of the Register for COM Interop option pretty thoroughly.

The trick, of course, is to set ComVisible to true”.