vb.net 无法转换为类型库 - 错误:找不到元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15629309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not be converted to a type library - Error: Element not found
提问by Jeremy Thompson
NOTE: I am answering my own question in the event it helps others in the future.
注意:如果将来可以帮助其他人,我将回答我自己的问题。
I'm getting the error:
我收到错误:
The assembly "C:\XYZ.dll" could not be converted to a type library. Type library exporter encountered an error while processing 'XYZ'. Error: Element not found.
程序集“C:\XYZ.dll”无法转换为类型库。类型库导出程序在处理“XYZ”时遇到错误。错误:未找到元素。
Here is the code that causes the problem:
这是导致问题的代码:
[Guid("7a4e9867-96a7-43f0-9492-0327b9053853"),
ClassInterface(ClassInterfaceType.None)]
public class TimeSeriesPoint
{
public string Date { get; set; }
public float Value { get; set; }
}
[Guid("7a4e9867-96a7-43f0-9492-0327b9053853"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IDataHelper
{
//RCOMServerLib.IStatConnector Connector { set; }
string Text { set; }
void DoCallback();
回答by Jeremy Thompson
I was using the same GUID from the AssemblyInfo file:
我使用的是 AssemblyInfo 文件中的相同 GUID:
[assembly: Guid("7a4e9867-96a7-43f0-9492-0327b9053853")]
You need to use unique GUIDs to resolve the error:
您需要使用唯一的 GUID 来解决错误:
[Guid("C25D485B-F7DE-4F1C-99FE-FFAF5A219B77"),
ClassInterface(ClassInterfaceType.None)]
public class TimeSeriesPoint
{
public string Date { get; set; }
public float Value { get; set; }
}
[Guid("FA6F70DD-CDD0-4FF3-94BA-E2B94E68321D"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IDataHelper
{
//RCOMServerLib.IStatConnector Connector { set; }
string Text { set; }
void DoCallback();
To get unique GUIDs in Visual Studio click Tools Menu > Create GUID > select the 4th option Registry Format> Copy:
要在 Visual Studio 中获取唯一的 GUID,请单击工具菜单 > 创建 GUID > 选择第 4 个选项注册表格式> 复制:


参考:http: //social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/a440f695-652c-46d2-bb52-650c6227d3e9
回答by bvj
Similar problem, but with the final error statement:
类似的问题,但最终的错误语句是:
Error: Error loading type library/DLL.
In my case, there was a referenced project/assembly that didn't have its tlbgenerated.
就我而言,有一个没有tlb生成的引用项目/程序集。
However, running regasmmanually worked. It generated the tlbfor both the referenced project/assembly and the target, Acme.Widgets.dll. And there were no explicit references to the related project specified on the regasmcommand line:
但是,regasm手动运行有效。它tlb为引用的项目/程序集和目标生成了Acme.Widgets.dll. 并且没有对regasm命令行上指定的相关项目的明确引用:
@ECHO OFF
pushd "%~dp0"
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\regasm Acme.Widgets.dll /tlb Acme.Widgets.tlb /codebase
popd
pause
I eventually realized the referenced project/assembly didn't have the Register for COM interopsetting enabled within Visual Studio. Figured it was enough to have it enabled for the target only, but that wasn't the case.
我最终意识到引用的项目/程序集没有在 Visual Studio 中启用注册 COM 互操作设置。认为只为目标启用它就足够了,但事实并非如此。
The referenced project/assembly began its life serving an ordinary .Net app where COM wasn't a factor.
引用的项目/程序集开始其生命周期,服务于一个普通的 .Net 应用程序,其中 COM 不是一个因素。

