Exception System.Runtime.InteropServices.COMException (0x800A03EC): Cannot insert object

fullstackvale 1 Reputation point
2021-01-25T12:01:59.07+00:00

In Windows form Application, Facing this exception System.Runtime.InteropServices.COMException (0x800A03EC): Cannot insert object.

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

at Microsoft.Office.Interop.Excel.Shapes.AddOLEObject(Object ClassType, Object Filename, Object Link, Object DisplayAsIcon, Object IconFileName, Object IconIndex, Object IconLabel, Object Left, Object Top, Object Width, Object Height)

Using:
Office 365 and OS windows 10
Application:Windows Application
Target framework: .NET Framework 4.5
Reference: Microsoft.Office.Interop.Excel (version: 14.0.0.0)

I write a function in window application that add pdf file into Excel sheet.
But I got this error System.Runtime.InteropServices.COMException (0x800A03EC): Cannot insert object
at method AddOLEObject() .

            //Insert ISO_LAYOUT pdf-drawing as object
            if (utilities.ctos(drCurrent["drawings"]) != "" && IncludeDetailAttachments)
            {
                        Excel.Shape shape = wsCurrent.Shapes.AddOLEObject(
                        ClassType: Type.Missing,
                        Filename: copyToFile,
                        Link: false,
                        DisplayAsIcon: true,
                        IconFileName: "",
                        IconIndex: 0,
                        IconLabel: "",
                        Left: Type.Missing,
                        Top: Type.Missing,
                        Width: Type.Missing,
                        Height: Type.Missing);
                        shape.Fill.ForeColor.RGB = 500;
                        //shape.Fill.UserPicture(WSCommon.Properties.Settings.Default.surfaceDrawingPath + "Binders.png");
                        shape.Width = 15;
                        shape.Height = 17;
                        shape.Left = (float)iconCell.Left + (float)345;
                        shape.Top = (float)iconCell.Top + (float)1;

                        shape.Locked = false;
                        shape.Name = "Detail attachment " + drCurrent["lv1"].ToString() + drCurrent["lv2"].ToString() + drCurrent["lv3"].ToString() + drCurrent["lv4"].ToString() + drCurrent["lv5"].ToString() + drCurrent["lv6"].ToString();
                        Marshal.ReleaseComObject(shape);

            }
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
{count} votes