Fullstackvale

Fullstackvale

  • NA
  • 13
  • 1.5k

System.Runtime.InteropServices.COMException (0x800A03EC)

Feb 8 2021 12:45 PM

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

  1. //Insert ISO_LAYOUT pdf-drawing as object  
  2. if (utilities.ctos(drCurrent["drawings"]) != "" && IncludeDetailAttachments)  
  3. {  
  4. Excel.Shape shape = wsCurrent.Shapes.AddOLEObject(  
  5. ClassType: Type.Missing,  
  6. Filename: copyToFile,  
  7. Link: false,  
  8. DisplayAsIcon: true,  
  9. IconFileName: "",  
  10. IconIndex: 0,  
  11. IconLabel: "",  
  12. Left: Type.Missing,  
  13. Top: Type.Missing,  
  14. Width: Type.Missing,  
  15. Height: Type.Missing);  
  16. shape.Fill.ForeColor.RGB = 500;  
  17. //shape.Fill.UserPicture(WSCommon.Properties.Settings.Default.surfaceDrawingPath + "Binders.png");  
  18. shape.Width = 15;  
  19. shape.Height = 17;  
  20. shape.Left = (float)iconCell.Left + (float)345;  
  21. shape.Top = (float)iconCell.Top + (float)1;  
  22. shape.Locked = false;  
  23. shape.Name = "Detail attachment " + drCurrent["lv1"].ToString() + drCurrent["lv2"].ToString() + drCurrent["lv3"].ToString() + drCurrent["lv4"].ToString() + drCurrent["lv5"].ToString() + drCurrent["lv6"].ToString();  
  24. Marshal.ReleaseComObject(shape);  
  25. }