C#Com互操作类方法在VB6中不可见?

C#Com互操作类方法在VB6中不可见?,c#,.net,dll,vb6,C#,.net,Dll,Vb6,我已经在.NET中创建了一个C#Com互操作类,并在我的开发机器上适当地注册了它,并且在程序集中将Com Visible设置为true。但是,当我在vb6应用程序中引用库时,我可以看到库名称、类名,但没有与它们关联的方法或属性 如果有人能帮我解决这个问题,我已经被困了很长一段时间了 这是我的班级: using System; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace

我已经在.NET中创建了一个C#Com互操作类,并在我的开发机器上适当地注册了它,并且在程序集中将Com Visible设置为true。但是,当我在vb6应用程序中引用库时,我可以看到库名称、类名,但没有与它们关联的方法或属性

如果有人能帮我解决这个问题,我已经被困了很长一段时间了

这是我的班级:

using System;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace VNDBUtils
{
public enum VNConstants : long
{
    cenMySQLDataStore = 32
}

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("CF4EFB82-6EE1-4A84-9CA9-07B135888B68")]
[ComVisible(true)]
public interface IVNSqlFormatter
{
    //Properties
    long DS_Type { get; set; }
    string DS_Query { get; set; }

    //Methods
    string Format_Entity(string strString);
    string MqStrMan_MakeStringEndWith(string strString, string strMatch);
    bool MqStrMan_StringEndsWith(string strString, string strMatch);
    string MqStrMan_MakeStringStartWith(string strString, string StrMatch);
    bool MqStrMan_StringStartsWith(string strString, string strMatch);
    string Right(string value, int length);
    string Left(string value, int maxLength);
    string Format_Value(string strString);
}



[ClassInterface(ClassInterfaceType.None)]
[Guid("3884D59D-AB76-41E7-82B6-21C66DBDCBF3")]
[ComVisible(true)]
public class VNSqlFormatter : IVNSqlFormatter
{

    private const string SQUARE_LEFT = "[";
    private const string SQUARE_RIGHT = "]";

    public long DS_Type { get; set; }
    public string DS_Query { get; set; }

    public string Format_Entity(string strString)
    {           
        strString = strString.Trim();

        if (DS_Type == (long)VNConstants.cenMySQLDataStore)
        {
            return strString;
        }
        else
        {
            return MqStrMan_MakeStringEndWith(MqStrMan_MakeStringStartWith(strString, SQUARE_LEFT), SQUARE_RIGHT);
        }

    }

    public string MqStrMan_MakeStringEndWith(string strString, string strMatch)
    {
        if (MqStrMan_StringEndsWith(strString, strMatch) == false)
        {
            return strString + strMatch;
        }
        else
        {
            return strString; 
        }

    }

    public bool MqStrMan_StringEndsWith(string strString, string strMatch)
    {
        return String.Equals(Right(strString, strMatch.Length), strMatch);

    }

    public string MqStrMan_MakeStringStartWith(string strString, string strMatch)
    {
        if (MqStrMan_StringStartsWith(strString, strMatch) == false)
        {
            return strMatch + strString;
        }
        else
        {
            return strString; 
        }
    }

    public bool MqStrMan_StringStartsWith(string strString, string strMatch)
    {
       return String.Equals(Left(strString, strMatch.Length), strMatch);
    }

    public string Right(string value, int length)
    {
        if (String.IsNullOrEmpty(value))
        {
            return String.Empty;
        }

        return value.Length <= length ? value : value.Substring(value.Length - length);
    }

    public string Left(string value, int maxLength)
    {
        if(String.IsNullOrEmpty(value))
        {
            return String.Empty; 
        }

        maxLength = Math.Abs(maxLength);
        return value.Length <= maxLength ? value : value.Substring(0, maxLength);
    }

    public string Format_Value(string strString)
    {
            return strString.Replace("'", "''");
    }

}
使用系统;
使用System.Linq;
使用系统文本;
使用System.Runtime.InteropServices;
名称空间VNDBUtils
{
公共枚举常量:长
{
cenMySQLDataStore=32
}
[接口类型(ComInterfaceType.InterfaceIsDual)]
[Guid(“CF4EFB82-6EE1-4A84-9CA9-07B135888B68”)]
[ComVisible(true)]
公共接口IVNSqlFormatter
{
//性质
长DS_类型{get;set;}
字符串DS_查询{get;set;}
//方法
字符串格式\实体(字符串字符串字符串);
字符串MqStrMan_MakeStringEndWith(字符串strString,字符串strMatch);
bool MqStrMan_StringEndsWith(字符串字符串,字符串格式);
字符串MqStrMan_MakeStringStartWith(字符串strString,字符串StrMatch);
bool MqStrMan_StringStartsWith(字符串strString,字符串strMatch);
字符串右键(字符串值,整数长度);
左字符串(字符串值,int maxLength);
字符串格式\u值(字符串strString);
}
[ClassInterface(ClassInterfaceType.None)]
[Guid(“3884D59D-AB76-41E7-82B6-21C66DBDCBF3”)]
[ComVisible(true)]
公共类VNSqlFormatter:IVNSqlFormatter
{
private const string SQUARE_LEFT=“[”;
private const string SQUARE_RIGHT=“]”;
公共长DS_类型{get;set;}
公共字符串DS_查询{get;set;}
公共字符串格式\u实体(字符串字符串)
{           
strString=strString.Trim();
if(DS_Type==(长)vncants.cenMySQLDataStore)
{
返回字符串;
}
其他的
{
返回MqStrMan_MakeStringEndWith(MqStrMan_MakeStringStartWith(strString,左方),右方);
}
}
公共字符串MqStrMan\u MakeStringEndWith(字符串strString,字符串strMatch)
{
if(MqStrMan_StringEndsWith(strString,strMatch)=false)
{
返回strString+strMatch;
}
其他的
{
返回字符串;
}
}
公共布尔MqStrMan\U StringEndsWith(字符串字符串、字符串格式)
{
返回字符串.Equals(右(strString,strMatch.Length),strMatch);
}
公共字符串MqStrMan\u MakeStringStartWith(字符串strString,字符串strMatch)
{
if(MqStrMan_StringStartsWith(strString,strMatch)=false)
{
返回标准格式+标准字符串;
}
其他的
{
返回字符串;
}
}
公共bool MqStrMan_StringStartsWith(字符串strString,字符串strMatch)
{
返回字符串.Equals(左(strString,strMatch.Length),strMatch);
}
公共字符串权限(字符串值,整数长度)
{
if(String.IsNullOrEmpty(value))
{
返回字符串。空;
}

返回值.Length是否编辑了AssemblyInfo.cs文件

通常,这是默认设置:

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e2e2a417-bd3d-414d-97f9-91196ce1c63a")]

您需要将
[assembly:ComVisible(false)]
设置为
true
注释中的讨论导致以下情况,
ProgId
属性未设置

[ClassInterface(ClassInterfaceType.None)]
[Guid(“3884D59D-AB76-41E7-82B6-21C66DBDCBF3”)]
[ComVisible(true)]
[ProgId(“VNDBUtils.VNSqlFormatter”)]
公共类VNSqlFormatter:IVNSqlFormatter
{
/*实施信息*/
}

认为这太长,无法作为注释添加到文档中

ProgID应该是自动生成的。而且它似乎已经作为您手动添加的字符串生成了

根据微软的文档

导出过程还会自动生成一个程序化的 标识符(ProgId),通过组合命名空间和类型名。对于 例如,为托管LinkedList类生成的ProgId如图所示 在前面的示例中,是A.B.LinkedList

组合名称空间 和类型名称可能导致无效的ProgId。ProgId限制为 39个字符,不能包含除 为避免这些限制,您可以在 源代码,而不是允许 导出为您生成标识符的过程


如果将ProgID属性作为测试取出,则可以检查编译时创建的typelib(使用类似OleView的工具)并查看它正在生成的ProgID。可能它生成的ProgID对VB6无效,但从示例中的代码来看,情况似乎并非如此。

在类上看不到
ProgID
属性,即
ProgID(“VNDBUtils.VNSqlFormatter”)
。可能有问题,也可能没有问题,我知道我所有的COM互操作类上都有一个。我不知道是否有必要,我会尝试一下,然后再给你回复。谢谢你的提示!还有,
.tlib
文件是否正在生成?是的,我认为问题出在ProgId上,因为它现在似乎工作正常!谢谢:)-我没有有足够的代表投票,虽然我会,如果我没有问题,我会添加它作为一个答案,这样我们就可以把它从队列中拿出来。是的,我已经设置为真。