我创建了一个C#类库,我通过VB 6.0应用程序使用它。但是当我尝试调用任何方法(返回一个字符串)时,它会给我一个自动化错误。否则,C#类运行正常。

知道为什么吗?

有帮助吗?

解决方案

正如fbinder所说,你应该强烈地签署你的程序集,并使用一些属性。我们使用(成功)的属性是:

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

其他提示

你应该强烈签署你的类库,用regasm注册它并把它放在你的类定义之前:

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

此外,您应该定义一个接口以显示所需的方法。界面应具有以下属性:

 [Guid("Interface GUID")]
 [ComVisible(true)]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top