gpt4 book ai didi

c# - 警告 MSB3391 : does not contain any types that can be unregistered for COM Interop

转载 作者:太空狗 更新时间:2023-10-29 17:31:53 24 4
gpt4 key购买 nike

我使用 VS2005 制作了一个简单的 C# DLL(这是一个更大项目的一部分)。我需要通过 VBA 代码在 Excel 中使用 DLL,因此我在程序集上使用 COM Interop。我正在尝试让构建过程自动生成必要的 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*/
}
}

最佳答案

  1. 您需要有不带任何参数的 ctor。
  2. 你应该有 GuidAttributeProgIdAttribute围绕类。
  3. 最好将程序集标记为 ComVisible(false) 并明确标记需要导出的类。
  4. 为您的类使用接口(interface)。
  5. 确保您在程序集级别具有 GuidAttribute。

    [Guid("<PUT-GUID-HERE-1>")]
    [ComVisible(true)]
    interface IFoo
    {
    void DoFoo();
    }

    [Guid("<PUT-GUID-HERE-2>")]
    [ComVisible(true)]
    [ProgId("ProgId.Foo")]
    class Foo : IFoo
    {
    public void DoFoo()
    {
    }
    }

关于c# - 警告 MSB3391 : <DLL> does not contain any types that can be unregistered for COM Interop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/853553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com