My problem is that I have a .NET project with like 100+ classes visible to COM. Classes are published to COM using the AutoDual attribute on the class. My problem is that I would like to let the compiler auto generate the COM Interface (hence this AutoDual) BUT I would like to be able to specify the GUID for the generated interface.
The goal is to make sure that small changes like:
- adding a method
- modifying a method that is not being used by a specific client
- increasing the version number of my DLL
won't break the clients (those using early binding) and force them to recompile.
I know (read here: Why should I not use AutoDual?) that a solution for that would be to create the 100+ interfaces manually and give them a GUID and DispId for each method so the changes mentionned above would no longer break older clients. However, I would like to avoid actually writing those interfaces manually, and having to maintain them when new methods needs to be added in both the class and interface.
So far I have managed to "automatically" publish those classes to COM without writing COM specific code by using PostSharp to inject the following attributes:
On classes:
- ComVisible(true)
- ClassInterfaceType.AutoDual
- GUID("A guid of my own automatically generated but invariant for a gievn class FullName")
On public methods and properties:
- DispId(xx) // where xx is again a dispId generated but invariant for a given class name/method name couple.
Having done that :
- the class GUID are invarriant what ever changes I make to them
- the DispId are also invarriant on the generated interface
Only the Interface GUID poses problem as it varies every time a method is added.
What I now need would be a way to ensure the generated interface for a given class always has the same GUID, by either:
- a specific attribute i don't know of, like 'AutoDualInterfaceGuid("My GUID") on the class
- a pre compilation process to generate the interfaces, with a GUID of my choice
- a post compilation process to modifiy the GUID of generated COM interfaces
- a way to modify the default generation of COM Interfaces in order to place my GUID logic in there.
Any idea on how to set a specific GUID for a generated COM Interface would be much appreciated.