Bhaskar
Bhaskar

Reputation: 10681

Automation Error in VB 6.0 from a C# class

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?

Upvotes: 1

Views: 2592

Answers (2)

Fabio Vinicius Binder
Fabio Vinicius Binder

Reputation: 13214

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)]

Upvotes: 1

Ant
Ant

Reputation: 5215

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();
}

Upvotes: 1

Related Questions