Skip to content

Glass.Mapper.MapperException: Service has been disposed, cannot create object #455

@kcrnac

Description

@kcrnac

Hello everyone 🙂

we started getting above mentioned exception which is basically identical to already opened but not resolved ticket: #299

It seems that issue happens when we're trying to get the item by an interface that has IEnumerable as a property (child items).

Sitecore version: 10.0
Glass mapper version: 5.8.180

Our GlassMapperConfigurator

serviceCollection.AddScoped<ISitecoreService>(provider => new SitecoreService(Context.Database));
serviceCollection.AddScoped<IMvcContext>(provider => new MvcContext(provider.GetService<ISitecoreService>()));
serviceCollection.AddScoped<IRequestContext>(provider => new RequestContext(provider.GetService<ISitecoreService>()));

All our controllers and services are defined as Scoped

We have a wrapper around SitecoreService which is used to get these items in the following way:

var page = _pagesService.GetPage<IProductAdditionalInformation>(ItemConstants.ProductDetailsPageId);

SitecoreService is injected via the constructor, and all Interfaces which we use are defined as Cache Enabled (We DO NOT have globally defined Always On Cache for models/interfaces):

[SitecoreType(Cache = Cache.Enabled, TemplateId = ProductAdditionalInformationConstants.TemplateIdString)]
public partial interface IProductAdditionalInformation : IGlassBase
{

    [SitecoreField(ProductAdditionalInformationConstants.WarningsFieldName)]
    IEnumerable<IWarning> Warnings { get; set; }
}

Exception trace

8464 10:54:31 ERROR Failed to map field {01A28A90-F018-4262-902A-FAB348A08874} with value {F5B07D17-1492-4B4B-8D57-7A4B98A301FE}
Exception: Glass.Mapper.MapperException
Message: Failed to map field {01A28A90-F018-4262-902A-FAB348A08874} with value {F5B07D17-1492-4B4B-8D57-7A4B98A301FE}
Source: Glass.Mapper.Sc
   at Glass.Mapper.Sc.DataMappers.AbstractSitecoreFieldMapper.GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\AbstractSitecoreFieldMapper.cs:line 128
   at Glass.Mapper.Sc.DataMappers.AbstractSitecoreFieldMapper.MapToProperty(AbstractDataMappingContext mappingContext) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\AbstractSitecoreFieldMapper.cs:line 97
   at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.LoadValue(AbstractPropertyConfiguration propertyConfiguration) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:line 121
   at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.Intercept(IInvocation invocation) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateInterface\InterfacePropertyInterceptor.cs:line 85
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.IProductAdditionalInformationProxy.get_Warnings()
   at ProductMappingService.GetWarrantyInformation(Product product, IProductAdditionalInformation page, String host) in E:\jenkins_docker\workspace\GDM\sourcecode\sc\src\Feature\Components\api\Services\ProductMappingService.cs:line 628
   at ProductMappingService.MapToProductDetails(Product product, String language, IProductAdditionalInformation page, String host) in E:\jenkins_docker\workspace\GDM\sourcecode\sc\src\Feature\Components\api\Services\ProductMappingService.cs:line 83
   at ProductsApiController.GetProductDetails(String productCode, String language) in E:\jenkins_docker\workspace\GDM\sourcecode\sc\src\Feature\Components\api\Controllers\ProductsApiController.cs:line 149

Nested Exception

Exception: Glass.Mapper.MapperException
Message: Service has been disposed, cannot create object
Source: Glass.Mapper
   at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper\AbstractService.cs:line 126
   at Glass.Mapper.Sc.SitecoreService.RunCreateType(Item item, GetOptions options, Dictionary`2 parameters) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\SitecoreService.cs:line 349
   at Glass.Mapper.Sc.SitecoreService.GetItem(GetItemOptions options) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\SitecoreService.cs:line 338
   at Glass.Mapper.Sc.DataMappers.SitecoreFieldTypeMapper.GetFieldValue(String fieldValue, SitecoreFieldConfiguration config, SitecoreDataMappingContext context) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\SitecoreFieldTypeMapper.cs:line 47
   at Glass.Mapper.Sc.DataMappers.SitecoreFieldIEnumerableMapper.<>c__DisplayClass4_0.<GetFieldValue>b__1(String x) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\SitecoreFieldIEnumerableMapper.cs:line 43
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Glass.Mapper.Sc.DataMappers.SitecoreFieldIEnumerableMapper.GetFieldValue(String fieldValue, SitecoreFieldConfiguration config, SitecoreDataMappingContext context) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\SitecoreFieldIEnumerableMapper.cs:line 43
   at Glass.Mapper.Sc.DataMappers.AbstractSitecoreFieldMapper.GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\DataMappers\AbstractSitecoreFieldMapper.cs:line 115

Please let me know if anyone have experienced the same issue and have a proper solution. @mikeedwards83
FYI @JamieG

Our next step is:

  • Try to disable lazy loading manually on GetItem call (even though lazy loading should be disabled by default if model Cache is enabled - correct me if I am wrong)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions