Paste from C# fails with System.Runtime.InteropServices.COMException crossed a native/managed boundary on some machines RRS feed

  • Question

  • When I paste to EXCEL 2010 from a C# application I get this error on some machines and not others

      Message=Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))
           at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
           at System.Windows.Forms.DataObject.GetDataIntoOleStructs(FORMATETC& formatetc, STGMEDIUM& medium)
           at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium)
           at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium)

    ExcelRange = HyperlinkSheet.get_Range(
    HyperlinkSheet.Paste(MyExcel.NoValue, MyExcel.NoValue);

    The pasted data is three tab separated columns and each row ends with an environment.newline.

    The error occurs 10 times per execution.

    Any thoughts on what I can do to prevent this?

    Thanks, have a great week-end.

    Tom G.

    Friday, July 24, 2015 5:03 PM


  • Hi Tom G,

    Based on the exception, the issue seems relative to the structure that you were setting is invalid. I would suggest that you try to pate the object manually in Excel application to see whether the issue could be reproduced.

    If yes, I suggest that you reopen a new thread in C# forum for using the Clipboards object.

    In addition, it seem that you want to copy the structure data from other source. As far as I know, we can also use ADO.Net to write data into spreadsheets or we can loop the data source and set the value cell by cell as a workaround.

    Regards & Fei

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 27, 2015 2:58 AM