Search code examples
c#.netvb.netcom

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


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();

Solution

  • 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