我创建了一个 C# 类库,并通过 VB 6.0 应用程序使用它。但是当我尝试调用任何方法(返回一个字符串)时,它会给我一个自动化错误。否则 C# 类运行良好。
知道为什么吗?
我创建了一个 C# 类库,并通过 VB 6.0 应用程序使用它。但是当我尝试调用任何方法(返回一个字符串)时,它会给我一个自动化错误。否则 C# 类运行良好。
知道为什么吗?
您应该对您的类库进行强签名,使用 regasm 注册它并将其放在您的类定义之前:
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("Class GUID")]
此外,您应该定义一个接口来公开所需的方法。该接口应具有以下属性:
[Guid("Interface GUID")]
[ComVisible(true)]
正如 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();
}