glass-mapper - GlassMapper 升级后 SitecoreTypeCreationContext 抛出异常
问题描述
我遇到了异常:
内部异常:对象引用未设置为对象的实例。在 Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)
在 InstantiateObject 的创建上下文中,它不为空,它是填充的项目。如果我添加 typeOf(TItem) 那么它会在 TItem cast 时崩溃,如果我评论它会在 instatinate 时崩溃。我试图删除 ConstructorParameter 但即使在这种情况下它也会崩溃升级前的代码:
var creationContext = new SitecoreTypeCreationContext
{
SitecoreService = sitecoreContext,
RequestedType = typeof(TItem),
ConstructorParameters = new object[0],
Item = item,
InferType = false,
IsLazy = true,
Parameters = new Dictionary<string, object>()
};
var result = sitecoreContext.InstantiateObject(creationContext) as TItem;
升级后的代码
var creationContext = new SitecoreTypeCreationContext
{
SitecoreService = mvcContext.SitecoreService,
Item = item,
Parameters = new Dictionary<string, object>(),
Options = new GetOptions()
{
//Type = typeof(TItem),
InferType = false,
Lazy = LazyLoading.Enabled,
ConstructorParameters = new List<ConstructorParameter>()
}
};
var result= mvcContext.SitecoreService.InstantiateObject(creationContext) as TItem;
我可能错过了配置或 RequestedType 它不等于 Option.Type?
解决方案
推荐阅读
- matlab - 是否可以将 Matlab 与 Preempt_RT 一起使用?
- flutter - Flutter CupertinoButton 子项未正确对齐
- google-apps-script - 查找 D 列中数据的最后一行,从 Google App Script 中的第 4 行开始搜索
- node.js - 多文档操作的nodeJs mongoose事务
- ssl-certificate - 使用 Certbox 的域质询失败
- python - ValueError: int() 以 10 为底的无效文字:'\ufeff615'
- sql - 当源表名和目标表名传入参数时,使用存储过程动态执行Merge Statement
- java - 注释异常:mappedBy 引用了一个未知的目标实体属性
- python - 散点图显示转换后的 timedelta64 值错误
- swift - Xamarin 访问 iOS 绑定 QualtricsSurveyViewController