【问题标题】:CreateObject("...") in VBScript fails to create a VB.Net class library com object (Windows Server 2000)VBScript 中的 CreateObject("...") 无法创建 VB.Net 类库 com 对象 (Windows Server 2000)
【发布时间】:2013-08-25 23:53:27
【问题描述】:

我正在使用 ASP 和 VBScript 编写应用程序。我只能找到一个为 .Net 应用程序编写的库。因此,我尝试创建一个类库包装器并使用 VB.Net(Microsoft Visual Basic 2010 Express)将其编译为 DLL。

DLL 在我自己的桌面上工作(Windows 7),但在服务器(Server 2000)中失败。

错误信息是“系统找不到指定的文件”

服务器配置

操作系统:Microsoft Windows 2000 Server (SP4)

已安装.Net 框架:v2.0.50727

我在测试项目中编写的代码只是一个什么都不做的类。

Imports System.IO
Imports System

<ComClass(Object1.ClassId, Object1.InterfaceId, Object1.EventsId)> _
Public Class Object1
#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "f5dcfb08-7a83-4501-bd89-03e38cad819c"
    Public Const InterfaceId As String = "8a313e0b-60e5-4ff4-8a7d-e7b1582eec71"
    Public Const EventsId As String = "fe55f7d8-691f-4c76-968a-37019fa9bb53"
#End Region

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Hello()
        '...
    End Sub
End Class

我做了什么:

  • 在编译选项中选择“.NET Framework 2.0”

  • 在我自己的桌面上编译

  • 将 Bin\Release 中的所有文件直接复制到服务器上的文件夹中。

  • 使用 Regasm.exe 在服务器上成功注册 DLL

但不能使用 VB6 或 VBScript 创建 Object1。

这是我在 VBScript 中使用的脚本:

Option Explicit

Dim TestObject
Set TestObject = CreateObject("TestComObject.Object1")

任何帮助将不胜感激!

亚历克斯

【问题讨论】:

  • 在服务器上下载 DependencyWalker 并在您的包装 DLL 上运行它。完全有可能无法解决其中一个依赖项。不幸的是,正如您所发现的那样,Windows 在向您提供有关缺失内容的具体细节方面很糟糕。

标签: vb.net com asp-classic vbscript vb6


【解决方案1】:

检查以下清单:

1) 确保将程序集编译为 32 位(在 VB.NET 项目设置中)

2) 为您的程序集起一个强名称 (http://msdn.microsoft.com/en-us/library/xc31ft41.aspx)。 您也可以在 VB.NET 项目设置中进行配置。

3) 为 .NET 2.0 使用 RegAsm (C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe)

4) 使用“/codebase”开关调用 RegAsm

5) 在使用 ASP 进行测试之前,请尝试使用 WScript.exe 从命令行运行测试脚本。

【讨论】:

  • 谢谢!第 4 点)正好解决了我遇到的问题。我已经尝试不使用第 2 点),它看起来也可以正常工作。
  • 不客气!我会自己记下不需要强名称。
  • 我按照您的步骤进行了所有操作,发现如果您使用的是 64 位操作系统,那么您将需要 64b 版本的 regasm:C:\Windows\Microsoft.NET\Framework64\v2。 0.50727\regasm.exe
猜你喜欢
  • 1970-01-01
  • 2016-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 1970-01-01
相关资源
最近更新 更多