我有一个Sitecore 8.1 CD实例。我也有一些代码需要在Master数据库中创建一个内容项。 (我知道这是一个禁忌,但我现在只需要弄清楚)当我的代码试图使用Glass Mapper创建一个内容项时,我得到一个错误。这里是代码片段和错误消息。我只是想了解错误的含义。我有一个感觉,这只是一个配置问题。此代码在我们的Sitecore CM服务器上正常工作。所以我希望通过简单地调整我们的CD服务器上的配置,我可以得到这个工作。到目前为止,我已经在ConnectionStrings.config和Sitecore.config中重新启用了Master条目。但是这并没有解决这个问题。如何修复Glass Mapper错误 - 无法找到父项类型的配置?
SitecoreService service = new SitecoreService("master");
SimpleAes aes = new SimpleAes();
using (new SecurityDisabler())
{
Item parentItem = Factory.GetDatabase("master").GetItem("/sitecore/content/Non Page Content/Account Information/Shipping Addresses");
newAddress = service.Create(parentItem, newAddress); //THIS IS WHERE THE CODE FAILS
user.Addresses.Add(newAddress);
Utility.PublishItem(service.ResolveItem(newAddress));
id = aes.EncryptToString(newAddress.Id.ToString());
user.Addresses = user.Addresses;
user.Save();
}
错误消息:
Glass.Mapper.MapperException:未能找到父 项目类型的配置Sitecore.Data.Items.Item ---> System.NullReferenceException: 对象引用不设置为一个对象的实例。在在 Glass.Mapper.Context.GetTypeConfiguration [T](对象OBJ,布尔 doNotLoad,布尔checkBase) System.Object.GetType()在 Glass.Mapper.Sc.SitecoreService.Create [T,TK](TK parent,T newItem, Boolean updateStatistics,Boolean silent)---内部异常结束 堆栈跟踪---在Glass.Mapper.Sc.SitecoreService.Create [T,TK](TK parent,T newItem,Boolean updateStatistics布尔无声)