我使用VS2005制作了一个简单的C# DLL(它是一个更大项目的一部分)。我需要通过VBA代码在Excel中使用该DLL,因此我正在使用程序集上的COM互操作。我正在尝试使构建过程自动生成必要的TLB文件,以便我不需要在每次构建后去命令行并使用regasm。
我的问题是,尽管DLL编译和构建都很顺利,但它没有生成TLB文件。相反,在输出窗口中打印出标题中的错误。
我已经通过进入VS2005中的项目属性 -> 构建 -> 输出 -> 检查“注册COM互操作”来让其他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*/
}
}