NullReferenceException Commerce Server Web Service

本文关键字:Service Web Server Commerce NullReferenceException | 更新日期: 2023-09-27 18:30:31

我的代码:

        ws.CategoryConfiguration cc = new ws.CategoryConfiguration();
        cc.LoadChildProducts = true;
        cc.ChildProducts.SearchOptions.PropertiesToReturn = new string[] { "BasePrice" };

当我运行这个时,我在ChildProducts行上得到一个NullReferenceException。我知道string[]是一个对象,因为它就在那里,所以它必须是PropertiesToReturn的。有人知道问题是什么吗? LoadChildProducts工作没有任何问题。

NullReferenceException Commerce Server Web Service

您需要

更新SearchOptions对象,如下所示:

CatalogSearchOptions searchOptions = new CatalogSearchOptions();

然后你可以添加PropertiesToReturn,像这样:

searchOptions.PropertiesToReturn = "BasePrice";

最后,可以将searchOptions分配给 CategoryConfiguration.ChildProducts.SearchOptions 属性,如下所示:

cc.ChildProducts.SearchOptions = searchOptions;

它是子产品中的ChildProductsSearchOptions
确保它们在CategoryConfiguration的构造函数中初始化