Best Practice: .NET Class Library Exposed as COM

Best Practice: .NET Class Library Exposed as COM

Post by YmVhdWRldG » Thu, 26 Jan 2006 00:21:02

I've got a question regarding the best way to develop a .NET class library
that will be consumed in an application as an Automation object. My
particulars are VS.NET 2003 and C#.

Here's the list of questions I have based on my research:

1) Do I have to use an interface approach or just make whatever methods and
methods I want exposed publicly available?
2) If I'm still coding this class but want to test it out in VB6 as I go
along, do I have to give it a strong name, register it useing REGASM and put
it in the GAC?
3) If so, how do I unregister before I run REGASM each time?
4) I'm confused about strong names and incremental changes to a build.

I guess what I'm looking for are answers on how to develop such a class and
test it in the development environment so that incremental changes can be
tested easily.


Best Practice: .NET Class Library Exposed as COM

Post by Clive Dixo » Thu, 26 Jan 2006 01:05:32

Personally I would use an interface based approach and mark your assembly as
[assembly: ClassInterface(ClassInterfaceType.None)]. This means that COM
interfaces are only generated for the .NET interfaces and not for .NET

Without interfaces you would use ClassInterfaceType.AutoDual to create a COM
interface from the .NET class, and this can cause versioning headaches.
The default GUID generated by regasm for interfaces is unchanged with each
build so long as the method signatures remain the same (but beware that
changing the order does not change the GUID but will break COM
compatibility), but those for the classes will change as the assembly
version number changes (which will happen with each build if you have the
wizard generated AssemblyVersion("1.0.*") type of thing). Personally I would
rather use the regasm default GUID generation algorithm than have to create
my own guids for every single class. Note also that the autogenerated LIBID
will change with assembly version too.

If you want to do continuous build & test you would need to keep your
assembly version fixed or else give all your classes and the assembly LIBID
fixed GUIDs.

You don't need to put the assembly in the GAC - the regasm should write the
location of the implementing assembly in the registry so that COM will find