警告MSB3391:或其可DLL>不包含可以是未注册为COM互操作的任何类型 [英] warning MSB3391: <DLL> does not contain any types that can be unregistered for COM Interop
问题描述
我做了一个简单的C#DLL(这是一个更大的项目的一部分)使用VS2005。我需要的,所以我就用组装COM互操作通过VBA代码在Excel中使用DLL。我的努力使构建过程自动生成所需的TLB文件,这样我不需要去命令行,每生成后使用regasm。
我的问题是,虽然DLL编译和构建精细,它不会产生一个TLB文件。相反,在标题打印错误出在输出框
我在VS2005将项目的属性得到其他DLL打造TLB文件 - >构建 - >输出 - >检查的注册为COM互操作的。我也有 [汇编:标记有ComVisible特性(真)]在AssemblyInfo.cs中的
下面是源的问题DLL的总结和它的返回类型引用的DLL:
使用系统;
:使用System.IO;使用System.Runtime.InteropServices
;
使用SymbolTable;
命名空间ProblemLibrary
{
公共类Foo
{
公共美孚(字符串文件名)
{
$ ... b $ b}
//方法来读取文本文件到一个SymbolTable
公共SymbolTable BuildDataSet(字符串[]选择)
{
...
}
}
}
下面是SymbolTable.dll的总结。它认为ProblemLibrary使用返回类型
使用系统;
使用System.Collections.Generic;
命名空间SymbolTable
{
公共类SymbolTable
{
只读字典< SymbolInfoStub,串> _symbols =新词典< SymbolInfoStub,串>();
/ *与字典进行交互的方法剪断* /
}
}
- 您需要有构造函数没有任何PARAMS。
- 您应该具有的 GuidAttribute 和的 ProgIdAttribute 类左右。
- 其更好地纪念集会为标记有ComVisible特性(假)和马克明确需要出口的类。
- 您的课程使用的接口。
-
请确保您有GuidAttribute在装配水平。
[的Guid(< PUT-GUID-HERE-1>中)
[标记有ComVisible特性(真)]
接口IFoo的
{
无效DoFoo();
}
[的Guid(< PUT-GUID-HERE-2>中)
[标记有ComVisible特性(真)]
[的ProgId (ProgId.Foo)]
类Foo:IFoo的
{
公共无效DoFoo()
{
}
}
I've made a simple C# DLL (that's part of a much larger project) using VS2005. I need to use the DLL in Excel via VBA code so I am using COM Interop on the assembly. I am trying to make the build process automatically generate the necessary TLB file so that I don't need to go to the command line and use regasm after every build.
My problem is that although the DLL compiles and builds fine, it does not generate a TLB file. Instead, the error in the title prints out in the output box.
I've gotten other DLLs to build TLB files by going to the project's properties in VS2005 -> Build -> Output -> Check "Register for COM interop". Also I have [assembly: ComVisible(true)] in the AssemblyInfo.cs.
Here's the summary of the source for the problem DLL and the DLL that it references for a return type:
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)
{
...
}
}
}
Here is a summary of SymbolTable.dll. It holds a return type that ProblemLibrary uses.
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*/
}
}
- You need to have ctor without any params.
- You should have GuidAttribute and ProgIdAttribute around the classes.
- Its better to mark the assembly as ComVisible(false) and mark explicitly the classes that need export.
- Use interfaces for your classes.
Make sure the you have GuidAttribute in the assembly level.
[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() { } }
这篇关于警告MSB3391:或其可DLL>不包含可以是未注册为COM互操作的任何类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!