【问题标题】:c# excel dll - can't add a reference to the specified file - regasmc# excel dll - 无法添加对指定文件的引用 - regasm
【发布时间】:2012-09-10 21:45:20
【问题描述】:

在另一台计算机上部署和注册.Net Excel.dll 时,尝试在VBA 编辑器中添加对DLL 的引用时出现错误Can't add a reference to the specified file

我在Visual Studio 中的C# 中创建了Excel.dll,它在我的机器上使用Windows 7Office 2010 运行良好。在我的计算机上的Excel VBA 编辑器中添加对 dll 的引用没有问题。我的问题是部署在另一台运行VistaExcel 2007 的机器上。我把dll复制到这台电脑上,用regasm注册了dll。

谁能指出我正确的方向?这里是代码和 regasm:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe excelDll.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace TestDll
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Test
{
    public string HelloWorld
    {
        get
        {
            return "Hello World";
        }
    }

    public void sayGoodbye1()
    {
        MessageBox.Show("Say Goodbye");

    }

    public string sayGoodbye2()
    {
        return "Say Goodbye";
    } 
  }
}

【问题讨论】:

    标签: c# dll windows-vista excel-2007 regasm


    【解决方案1】:

    您需要为 excel 注册类型库才能在 References 中查看您的 dll。

    regasm.exe excelDll.dll /tlb:excelDll.tlb

    标记。

    【讨论】:

      【解决方案2】:

      我最近遇到并设法解决了这个问题 - 虽然我不能声称完全理解为什么我的解决方案有效。

      我的两个系统都运行 Windows 7 x64。一个有 Excel 2010,另一个有 Excel 2007。

      所有 C# 程序集都设置为“平台目标:任何 CPU”。主程序集设置为“注册 COM 互操作”。整个东西是使用由 Visual Studio 安装程序项目创建的 MSI 安装的。

      我发现如果我将 Visual Studio 安装程序项目“目标平台”设置为“x64”,那么它可以在 Excel 2010 中工作,但不能在 Excel 2007 中工作。相反,如果我将 Visual Studio 安装程序项目设置为“目标平台”到“x86”,它在 Excel 2007 中有效,但在 Excel 2010 中无效。

      遗憾的是,我无法在同一台机器上同时测试两个 Excel 版本 - 但至少这可能会为您工作!

      【讨论】:

      • 只是添加到我上面的帖子中 - 我收到了报告的“无法添加引用”错误,并且(如果我使用 CreateObject 而不添加引用)“许可证不可用”错误。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多