C# – Failed to create component ‘AxHost’ System.Runtime.InteropServices.COMException (0x80029C4A)

cnetuser-controls

I have created .Net usercontrol in C#. it is graphical control with a text box and listbox.
Now I want to use this control in legacy VC++ application.(native binary).
means I want to call manage code from unmanage code.

suppose my usercontrol name is xyz.dll.
I generated tlb file using tlbexp.exe and then i registered this control using below command line.
regasm xyz.dll /tlb:"C:\xyz.tlb" /codebase

I have checked my control using 'Activex control test container' (open studio 2005 and go to 'tools' menu)
I tested my .Net usercontrol on this tool and it worked fine.

then I created a sample C# window application. Under Toolbox, I right click and selected 'Choose Items' and selected
"COM component" tab. and choose my xyz.dll control.
now this contol is added into toolbox.

But when I drag this control onto window then i got below error.
Failed to create component 'AxHost'. The error message follows:

'System.Runtime.InteropServices.COMException (0x80029C4A): Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))
at System.Windows.Forms.Design.DocumentDesigner.AxToolboxItem.CreateComponentsCore(IDesignerHost host)
at System.Drawing.Design.ToolboxItem.CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
at System.Drawing.Design.ToolboxItem.CreateComponents(IDesignerHost host, IDictionary defaultValues)
at System.Windows.Forms.Design.OleDragDropHandler.CreateTool(ToolboxItem tool, Control parent, Int32 x, Int32 y, Int32 width, Int32 height, Boolean hasLocation, Boolean hasSize, ToolboxSnapDragDropEventArgs e)'
.

also give me some pointer "how to use .net usercontrol into legacy C# application"

Best Answer

Type the following in command prompt , regsvr32 "C:\Program Files\VideoLAN\VLC\axvlc.dll" to register dll file