Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not be converted to a type library - Error: Element not found

Tags:

c#

.net

vb.net

com

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();
like image 535
Jeremy Thompson Avatar asked Mar 26 '13 04:03

Jeremy Thompson


2 Answers

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.

like image 37
bvj Avatar answered Nov 14 '22 01:11

bvj


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:

enter image description here

Ref: http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/a440f695-652c-46d2-bb52-650c6227d3e9

like image 51
Jeremy Thompson Avatar answered Nov 14 '22 01:11

Jeremy Thompson