Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intuit QBO SDK Update Bill error generating the XML document Value of ItemElementName mismatches the type of System.Decimal

I am using Intuit QBO SDK v3 Intuit.Ipp.QueryFilter.QueryService(Of Bill) to get a collection of Bills filtered by Bill.Id. The collection is populated successfully. I want to modify just the BillableStatus of some of the ItemBasedExpenseLineDetail members of a Bill and update it with Intuit.Ipp.DataService.DataService.Update(Of Bill). Whether I actually modify any properties of the Bill or not, the Update method generates the following error:

Intuit.Ipp.Exception.SerializationException: There was an error generating the XML document. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Value of ItemElementName mismatches the type of System.Decimal; you need to set it to Intuit.Ipp.Data.ItemChoiceType.@UnitPrice. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBill.Write163_ItemBasedExpenseLineDetail(String n, String ns, ItemBasedExpenseLineDetail o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBill.Write181_Line(String n, String ns, Line o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBill.Write185_Bill(String n, String ns, Bill o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBill.Write186_Bill(Object o) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o, XmlSerializerNamespaces namespaces) at Intuit.Ipp.Utility.XmlObjectSerializer.Serialize(Object entity) --- End of inner exception stack trace --- at Intuit.Ipp.Utility.XmlObjectSerializer.Serialize(Object entity) at Intuit.Ipp.Core.Rest.RestHandler.PrepareRequest(RequestParameters requestParameters, Object requestBody, String oauthRequestUri) at Intuit.Ipp.DataService.DataService.Update[T](T entity)

The values of all the ItemBasedExpenseLineDetail members of the Bill seem to properly be Intuit.Ipp.Data.ItemChoiceType.UnitPrice as shown by a Watch or Immediate Window, for example:

?DirectCast(qboItem.Line(0).AnyIntuitObject, Intuit.Ipp.Data.ItemBasedExpenseLineDetail).ItemElementName

UnitPrice {2}

Any ideas how to perform the update without this error or where to look further?

like image 413
RJBreneman Avatar asked Mar 18 '23 04:03

RJBreneman


1 Answers

Aaaaaand, about as soon as I posted this question, I found the answer over on Intuit.Developer Community

I guess you have the default setting from SDK where request format is XMl and response is Json.

This causes serialization issues which you have mentioned above.

Please add the following lines in your code to have either both request/response in xml or boht in json format.

context.IppConfiguration.Message.Request.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Json;

context.IppConfiguration.Message.Response.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Json;

like image 128
RJBreneman Avatar answered Apr 26 '23 04:04

RJBreneman