我使用 VS2005 制作了一个简单的 C# DLL(这是一个更大项目的一部分)。我需要通过 VBA 代码在 Excel 中使用 DLL,因此我在程序集上使用 COM Interop。我正在尝试使构建过程自动生成必要的 TLB 文件,这样我就不需要在每次构建后转到命令行并使用 regasm。
我的问题是,虽然 DLL 编译和构建很好,但它不会生成 TLB 文件。相反,标题中的错误会在输出框中打印出来。
通过转到 VS2005 -> Build -> Output -> Check "Register for COM interop"中的项目属性,我已经获得了其他 DLL 来构建 TLB 文件。我还在AssemblyInfo.cs 中有[assembly: ComVisible(true)] 。
以下是问题 DLL 的源代码以及它为返回类型引用的 DLL 的摘要:
using System;
using System.IO;
using System.Runtime.InteropServices;
using SymbolTable;
namespace ProblemLibrary
{
public class Foo
{
public Foo(string filename)
{
...
}
// method to read a text file into a SymbolTable
public SymbolTable BuildDataSet(string[] selected)
{
...
}
}
}
这里是 SymbolTable.dll 的摘要。它拥有 ProblemLibrary 使用的返回类型。
using System;
using System.Collections.Generic;
namespace SymbolTable
{
public class SymbolTable
{
readonly Dictionary<SymbolInfoStub, string> _symbols = new Dictionary<SymbolInfoStub, string>();
/*methods that interact with Dictionary snipped*/
}
}