C#COM类 - DISP_E_UNKNOWNNAME [英] C# COM Class - DISP_E_UNKNOWNNAME
问题描述
我已经在C#中声明了一个COM可见类。代码如下:
[ComVisible(true)]
public class AComVisibleClass:TheParentClass
{
public bool SomeFunc(string id)
{
return true;
}
}
此类由工厂实例化
但是如果我尝试在VB脚本文件中访问,则 DISP_E_UNKNOWNNAME
异常抛出。
这是我们在这里工作的一个预先存在的库的一个新类。所有其他类都可以通过COM访问。整个库被编译成单个装配文件。我已经注册新的程序集使用 regasm
,但我仍然得到这个异常。
我试图调试COM调用使用VS2008。工厂类似乎能够实例化 AComVisibleClass
。只有当工厂尝试执行 SomeFunc
时,才会抛出上述异常。
我知道这听起来有点?)bit vague,但我不能公开真正的代码在这里。如果有人需要更多信息,请问我。
我可以想到这个问题的三个可能的原因:
原因1:在CreateObject中使用错误的名称:
我想你的VBScript代码调用
像
这样:
设置obj = CreateObject(MyLibrary.AComVisibleClass)
如果这是正确的,请打开注册表编辑器,并检查 HKEY_CLASSES_ROOT
键包含一个名为 MyLibrary.AComVisibleClass
的子键。
如果没有,那么你的库名可能不同于你的预期。搜索注册表 AComVisibleClass
以查找正确的库名称。
原因2:64位问题:
如果在64位操作系统上出现问题,原因可能是您的VBScript作为32位进程运行,C#COM
原因3:错误的函数名称:
您可能在脚本中使用错误的函数名称,例如 obj.SomeFnc(1)
而不是 obj.SomeFunc(1)
,或者您选择的函数名称是保留在VBScript中的关键字,或包含异常字符。
I have declared a COM visible class in C#. The code is as follows:
[ComVisible(true)]
public class AComVisibleClass : TheParentClass
{
public bool SomeFunc(string id)
{
return true;
}
}
This class is instantiated by a factory class, also COM accessible.
But if I try to access in a VB script file, a DISP_E_UNKNOWNNAME
exception is thrown.
This is a new class on a pre-existent library we have here at work. All other classes are accessible through COM. The whole library is compiled into a single assembly file. I have registered the new assembly using regasm
, but I still get this exception.
I've tried to debug the COM call using VS2008. The factory class seems to be able to instantiate the AComVisibleClass
. The aforementioned exception is thrown only when the factory tries to execute SomeFunc
.
I know this may sound a little(?) bit vague, but I cannot expose the real code here. If someone need more information, please ask me.
I can think of three possible reasons for this problem:
Reason 1: Wrong name used in CreateObject:
I suppose that your VBScript code calls something like this:
Set obj = CreateObject("MyLibrary.AComVisibleClass")
If this is correct, then please open the registry editor and check whether the HKEY_CLASSES_ROOT
key contains a subkey called MyLibrary.AComVisibleClass
.
If it does not, then your library name possibly is different than you expected. Search the registry for AComVisibleClass
to find the correct library name.
Reason 2: 64-bit issues:
If the problem happens on a 64-bit operating system, the reason could be that your VBScript runs as a 32-bit process and the C# COM DLL is 64-bit or vice versa.
Reason 3: Wrong function name:
You might be using the wrong function name in the script, e.g. obj.SomeFnc(1)
instead of obj.SomeFunc(1)
, or the function name you have chosen is a reserved keyword in VBScript or it contains unusual characters.
这篇关于C#COM类 - DISP_E_UNKNOWNNAME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!