Question

I have created a C# class library and I am using it through a VB 6.0 application. But when I try to call any method (which returns a string) it gives me an automation error. The C# class is running fine otherwise.

Any idea why?

Was it helpful?

Solution

As fbinder says, you should strong sign your assembly, and use some attributes. The attributes we use (successfully) are:

[ComVisible( true )]
[ClassInterface( ClassInterfaceType.None )]
[Guid( "00000000-0000-0000-0000-000000000000" )]
[ComDefaultInterface( typeof( IExposedClass ) )]
public class ExposedClass : IExposedClass
{
    //need a parameterless constructor - could use the default
    public ExposedClass() { }

    public string GetThing()
    {
        return "blah";
    }
}

[ComVisible( true )]
[Guid( "00000000-0000-0000-0000-000000000000" )]
[InterfaceType( ComInterfaceType.InterfaceIsIUnknown )]
public interface IExposedClass
{
    string GetThing();
}

OTHER TIPS

You should strong sign your class library, register it with regasm and put this before your class definition:

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("Class GUID")]

Also, you should define an Interface to expose the desired methods. The interface should have the attributes:

 [Guid("Interface GUID")]
 [ComVisible(true)]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top