System.InvalidOperationException:不期望

时间:2013-03-07 16:12:59

标签: intuit-partner-platform

我正在尝试将产品添加到QuickBooks,但我收到此错误:

错误:

{System.InvalidOperationException:XML文档中存在错误(1,2)。 ---> System.InvalidOperationException:不期望。    在Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderFaultInfo.Read3_FaultInfo()    ---内部异常堆栈跟踪结束---    在System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle,XmlDeserializationEvents事件)    在System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)    at Intuit.Ipp.Utility.XmlObjectSerializer.Deserialize [T](String message)}

这是我的代码:

    private Item BuildInventoryItemAddRq(JMAOrderDetail _OrderItem)
    {
        // Make sure we have a SKU value
        if (string.IsNullOrEmpty(_OrderItem.Sku))
        {
            ErrorMessageDataSource.Insert(new ErrorMessage(MessageSeverity.Info, "QBO", "OrderItemId " + _OrderItem.OrderId.ToString() + " has no SKU.  Using default QuickBooks Item Name of 'Unknown Item'"));
            _OrderItem.Sku = "Unknown Item";
        }

        // create the item as an inventoryitem in Quickbooks
        Item QBItem = new Item();
        QBItem.Active = true;
        QBItem.Name = _OrderItem.Sku;
        string _ItemName = IsProductVariantNamed(_OrderItem);
        //if (!string.IsNullOrEmpty(_ItemName))
        //{  // its a variant product
        //    _ItemName += "(" + _ItemName + ")";
        //    if (_OrderItem != null)
        //        QBItem.QtyOnHand = _OrderItem.StockQuantity;
        //    else
        //        QBItem.QtyOnHand = 0;
        //}
        //else
        //{ // regular product
        //    if (_OrderItem != null)
        //        QBItem.QtyOnHand = _OrderItem.StockQuantity;
        //    else
        //        QBItem.QtyOnHand = 0;
        //}

        QBItem.PurchaseDesc = _ItemName;
        //QBItem.SalesDesc = _ItemName;
        QBItem.PurchaseCost = new Money() { Amount = _OrderItem.Product.PurchaseCost };
        //QBItem.SalesPrice = (Double)_OrderItem.UnitPriceExclTax;
        QBItem.IncomeAccountRef = new AccountRef { AccountName = _qboSettings.ItemIncomeAcct };
        QBItem.COGSAccountRef = new AccountRef() { AccountName = _qboSettings.ItemCOGSAcct };
        QBItem.AssetAccountRef = new AccountRef() { AccountName = _qboSettings.ItemAssetAcct };

        try
        {
            Item it = dataServices.Add(QBItem);
            return it;
        }
        catch (Exception ex)
        {
            ErrorMessageDataSource.Insert(new ErrorMessage(MessageSeverity.Error, "QBO", String.Format("Error adding item : {0}", ex.ToString())));
            return new Item();
        }


    }

1 个答案:

答案 0 :(得分:2)

回答这个问题(来自约瑟夫) 指定QBItem.Type变量:QBItem.Type = ItemTypeEnum.Inventory; QBItem.TypeSpecified = true;

感谢
震动