在VB6.0中导致错误438的ComVisible C#DLL
我已经用C#(.NETV4)编写了一个DLL,我想在VB6.0项目中使用它。我基本上是在学习教程,最后上了这门课在VB6.0中导致错误438的ComVisible C#DLL,c#,.net,dll,vb6,com-interop,C#,.net,Dll,Vb6,Com Interop,我已经用C#(.NETV4)编写了一个DLL,我想在VB6.0项目中使用它。我基本上是在学习教程,最后上了这门课 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace CRUFL_CS_ExchangeRate { [Serializable] [ComVisible
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CRUFL_CS_ExchangeRate
{
[Serializable]
[ComVisible(true), ClassInterface(ClassInterfaceType.None), Guid("F5DCE88F-AD38-4a9a-9A69-0F8DC0EDB4E3")]
public class ExchangeUfl : IExchangeUfl
{
public double ConvertUSDollarsToCDN(double usd)
{
return (usd * 1.45);
}
public void bla()
{
}
public string t2()
{
return "t2";
}
public String test()
{
return "test";
}
}
}
这个接口呢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CRUFL_CS_ExchangeRate
{
[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("F6B3D6DB-E4C8-48A9-B9B5-324012E2E93F")]
interface IExchangeUfl
{
[DispId(1)]
double ConvertUSDollarsToCDN(double usd);
[DispId(2)]
String test();
[DispId(3)]
string t2();
[DispId(4)]
void bla();
}
}
我的AssemblyInfo.cs看起来像这样
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("CRUFL_CS_ExchangeRate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("CRUFL_CS_ExchangeRate")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: Guid("912fe53d-dfc9-4eec-bbca-7f2ed29d95dc")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
我已在项目属性中启用强名称签名,并且COM Interopt注册已关闭
我创建了这个项目,并通过“regasm.exc:\path\to\the\lib.DLL/codebase”注册了DLL,它显示在GAC中(我使用的是来自www.nirsoft.net的RegDllView)
在VB项目中,我可以创建对象,因此我假设注册工作正常。
但当我调用其中一个方法时,我得到一个运行时错误“438”:对象不支持此属性或方法
我的VB代码如下所示:
Dim testi As Object
Dim fab As Object
Set fab = CreateObject("CRUFL_CS_ExchangeRate.ExchangeUfl")
Set testi = fab.t2()
无论我调用哪种方法,我总是得到相同的错误:(
我错过什么了吗?我做错什么了吗?有什么想法吗
谢谢:)
/tlb
选项导出typelibCreateObject
语法。相反,添加对先前导出的typelib的引用提示:在COM公共签名/类名中避免使用下划线。VB6在某些边缘情况下使用特殊含义处理下划线。最好将其扼杀在萌芽状态。“它出现在GAC中”是完全错误的,与Regasm的/codebase选项完全不兼容。将其从GAC中删除,以便确保VB6程序不会使用尚未包含该成员的旧版本的DLL。嗯,注册的文件位于C:\Windows\Microsoft.Net\assembly\GAC_MSIL\CRUFL_CS_ExchangeRate\v4.0_1.0.0_e0中a5a78a5fa397d9\CRUFL_CS_ExchangeRate.dll,并且已存在几天,很可能是过时的版本缺少这些方法。我删除了它并重新注册了DLL。现在它指向我的c#项目目录。看起来很好,但是我得到了“Automatisierungsfehler.Das System konnte die angegebene Datei nicht finden.”(类似于“automatization error.System找不到文件”)?!使用SysInterals的进程监视器查看文件的查找位置。我建议您从使用VB.Net ComClass模板开始,然后在需要时切换到C#。VB.Net ComClass开箱即用,我们在生产中使用它们已有两年多了。确保使用新名称,以免与以前的类混淆。