Creating a assembly with a COM interface

  • Thread starter Thread starter msnews.microsoft.com
  • Start date Start date
M

msnews.microsoft.com

Hi all,
I am writing a COM aware C# lib. In this lib I want to create an assembly
that defines a COM interface and only a COM Interface. When I do this and
try to registist the assembly I get the error "COM Interop registration
failed. There are no registrable types in the built assembly." and the
assembly containing the coclass that implments the interface also fails with
the error "COM Interop registration failed. Could not find a type library
for assembly XXX".

I can get round the errors by adding a dummy coclass to the 'interface'
assembly, but I dont like this solution.

Does any one know how to create an assmbly that can register just a COM
Interface with no coclasses?

Steven Evans.
 
A real good book is by Andrew Troelsen on COM interop what you need to do is define an interface and have your class implement that interface

[InterfaceType(ComInterfaceType.InterfaceTypeIUnknown)
[Guid("paste guid here")
public interface IMyInterfac

...


[ClassInterfaceType(ClassInterfaceType.None)
[Guid("paste guid here")
public class MyClass : IMyInterfac

.... //Implement interfac


Make sure you have Register for COM Interop set to true in Configuration properties for the projec

You should create a strong name using sn -k mycomdll.snk (place in same directory as your solution) and set that path an
name in the AssemblyInfo.cs [assemby: KeyFileName("..\\..\\mycomdll.snk")

Then do a regasm mycomdll.dll to register the type

Then do a gacutil /i mycomdll.dll if you wish to place in the gac
 
Back
Top