Could not be converted to a type library - Error: Element not found
Solution 1
I was using the same GUID from the AssemblyInfo file:
[assembly: Guid("7a4e9867-96a7-43f0-9492-0327b9053853")]
You need to use unique GUIDs to resolve the error:
[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:
Solution 2
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 tlb
generated.
However, running regasm
manually worked. It generated the tlb
for both the referenced project/assembly and the target, Acme.Widgets.dll
. And there were no explicit references to the related project specified on the regasm
command line:
@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 interop setting enabled within Visual Studio. Figured it was enough to have it enabled for the target only, but that wasn't the case.
The referenced project/assembly began its life serving an ordinary .Net app where COM wasn't a factor.
Jeremy Thompson
Hello fellow SO'r, I am a developer with a long professional history of work with web and Microsoft technologies. I am passionate about C#, VB.Net, Winforms, Web (jQuery, ASP.Net, IIS), SQL and am into a lot of tools for DevOps, Debugging, Performance, Threading, IDE and etc. My background in coding started with VB and C++, then classic asp and onto .Net. At various times I have worked for Datacom, Massive Interactive, Macquarie Bank, GraysOnline.com, MLC, SKM/Jacobs Engineering, the Reserve Bank of Australia, National Australia Bank and more. The highlight of my career was working for Microsoft Australia in Professional Developer PSS. Solving developer support cases for Microsoft Gold and Premiere customers has helped me to answer on here. I like answering the bounty questions and helping people out who are really stuck, "as if your job depends on it". I currently work at the NAB Cloud Guild as a trainer, best practice engineer and escalation engineer across NAB for cloud matters. Dip. Business, MCP, MCAD.Net, MCSD.Net, MCT (06/07), AWS CP, AWS CSA, AWS SOA, AZ900, AZ204, AZ303, AZ304
Updated on June 19, 2022Comments
-
Jeremy Thompson almost 2 years
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.
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();
-
Jeremy Thompson over 4 yearsNice one, see comments in this answer, I think Reg for Com Interop should be more obvious when it's explicitly needed: stackoverflow.com/a/52050257/495455