SitecoreTypeCreationContext throws exception after GlassMapper upgrade

47 views Asked by At

I'm getting exception:

Inner Exception: Object reference not set to an instance of an object. at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)

At InstantiateObject the creation context it's not null, the item it's populated. If I add the typeOf(TItem) then it crashes there at TItem cast, if I comment then it crashes at instatinate. I tried to remove ConstructorParameter but even on that case it's crashing The code before upgrade:

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;

The code after upgrade

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;

I missed maybe a configuration or RequestedType it's not equal Option.Type?

0

There are 0 answers