Error 'Unable to cast object of type 'System.Object[*]' to type 'System.Object[]'.'

24 views
Skip to first unread message

Nam Vũ

unread,
Jul 16, 2024, 10:16:12 PM (5 days ago) Jul 16
to Excel-DNA
Hi, I am writing a small utility in Excel with Excel DNA. Including a code as follows:
public void Sub_Etransmit(IRibbonControl control)
{
    Excel.Application xApp = (Excel.Application)ExcelDnaUtil.Application;
    Excel.Workbook xBook = xApp.ActiveWorkbook;
    // This is the code I need to ask
    Array links = xBook.LinkSources(Excel.XlLink.xlExcelLinks);
}
When running the code it all notified the error 'Unable to cast object of type 'System.Object[*]' to type 'System.Object[]'.'. How can I fix this error?

Govert van Drimmelen

unread,
Jul 20, 2024, 2:07:59 AM (2 days ago) Jul 20
to Excel-DNA

I'm guessing LinkSources is returning a COM array which is 1-based, and so you need some special handling to use from C#. You  can't just assign to an 'Array' variable.

Googling the error message and COM might help.

-Govert


--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/9235df7a-4a6c-42ff-b454-ed7f7460f38an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages