CustomXMLNode.AddNode throws exception; type mismatch
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?!
This API is broken in NetOffice 1.7.3.0 and 1.7.4.3
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.