来自C#类的VB 6.0中的自动化错误 [英] Automation Error in VB 6.0 from a C# class

查看:80
本文介绍了来自C#类的VB 6.0中的自动化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了C#类库,并且正在通过VB 6.0应用程序使用它。但是,当我尝试调用任何方法(返回字符串)时,会出现自动化错误。

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.

知道为什么吗?

推荐答案

<正如fbinder所说,您应该对程序集进行强签名,并使用一些属性。我们成功使用的属性是:

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

这篇关于来自C#类的VB 6.0中的自动化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆