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
工作没有任何问题。
您需要
更新SearchOptions
对象,如下所示:
CatalogSearchOptions searchOptions = new CatalogSearchOptions();
然后你可以添加PropertiesToReturn
,像这样:
searchOptions.PropertiesToReturn = "BasePrice";
最后,可以将searchOptions
分配给 CategoryConfiguration.ChildProducts.SearchOptions
属性,如下所示:
cc.ChildProducts.SearchOptions = searchOptions;
它是子产品中的ChildProducts
或SearchOptions
。
确保它们在CategoryConfiguration
的构造函数中初始化