NetOffice icon indicating copy to clipboard operation
NetOffice copied to clipboard

CustomXMLNode.AddNode throws exception; type mismatch

Open netoffice-bot opened this issue 9 years ago • 2 comments

Issue by BogeyLab Wed, 06 Jul 2016 15:34:47 GMT Originally opened as https://netoffice.codeplex.com/workitem/22309


CustomXMLNode.AddNode seems to throw an exception due to a type mismatch. Tested in Excel 2007.

This is a copy of Microsoft's example for Custom XML Parts found under https://msdn.microsoft.com/en-us/library/office/ff864167.aspx

NetOffice.ExcelApi.Workbook workbook = /* .... this is set to a proper workbook reference */;

NetOffice.OfficeAPI.CustomXMLPart cxp1 = workbook.CustomXMLParts.Add("<invoice />");
NetOffice.OfficeApi.CustomXMLNode cxn = cxp1.SelectSingleNode("/invoice");


// the following line will throw a COMException exception
// InnerException: Exception has been thrown by the target of an invocation
//   -> InnerException: {"Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"}
cxp1.AddNode(( NetOffice.OfficeApi.CustomXMLNode)cxn, (string)"upcode", (string)"urn:invoice:namespace");

Edit: This works when doing cxp1.DocumentElement.AppendChildNode(...). Not quite sure if Microsoft's own example was wrong, or NetOffice causes an issue in the case described above?!

netoffice-bot avatar Jul 06 '16 13:07 netoffice-bot

This API is broken in NetOffice 1.7.3.0 and 1.7.4.3

jozefizso avatar Nov 01 '18 18:11 jozefizso

This API does not work because it requires the AddNode to be called in early bind fashion. As NetOffice uses late binding, this method cannot be used in NetOffice.

jozefizso avatar Jun 20 '20 20:06 jozefizso