I'm using Glass.Mapper v4.5.0.4 and Sitecore 8.2 (rev. 170407).
I'm doing an import into Sitecore and am using the SitecoreService.Save(T target) method for creating and saving items. I have the SitecoreService in a using statement like this:
using (this.SiteService = new SitecoreService(this.ImportDB))
{
// CRUD operations here...
}
The items I'm saving are all standard code-generated using TDS Code generation templates with glass attributes on the class and properties.
The service is working fine for MOST items (as I'm iterating thru them) where I'm able to either create or update the item and then save it back to sitecore. However, I get this random error at some point during the CRUD operations:
Exception: Glass.Mapper.MapperException
Message: Service has been disposed, cannot create object
Source: Glass.Mapper
at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)
at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateConcrete.LazyObjectInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies._ProviderTermProxy.get_CurrentItem()
at lambda_method(Closure , Object )
at Glass.Mapper.Sc.Configuration.SitecoreTypeConfiguration.ResolveItem(Object target, Database database)
at Glass.Mapper.Sc.DataMappers.SitecoreFieldTypeMapper.SetFieldValue(Object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
at Glass.Mapper.Sc.DataMappers.SitecoreFieldIEnumerableMapper.SetFieldValue(Object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
at Glass.Mapper.Sc.DataMappers.AbstractSitecoreFieldMapper.SetField(Field field, Object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
at Glass.Mapper.Sc.DataMappers.AbstractSitecoreFieldMapper.MapToCms(AbstractDataMappingContext mappingContext)
at Glass.Mapper.ExtensionMethods.ForEach[T](IEnumerable1 list, Action1 action)
at Glass.Mapper.Pipelines.ObjectSaving.Tasks.StandardSavingTask.Execute(ObjectSavingArgs args)
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.Run(T args)
at Glass.Mapper.Sc.SitecoreService.WriteToItem[T](T target, Item item, Boolean updateStatistics, Boolean silent)
at Glass.Mapper.Sc.SitecoreService.Save[T](T target, Boolean updateStatistics, Boolean silent)
I have no idea why this is happening. I'm clearly still inside the using statement when this happens so the service has not been disposed of yet. Here is the kicker: I can still use the service for subsequent items when i trap the error in a try/catch and just move on. So it's clearly NOT disposed of yet.
Has anyone run into this and resolved it? Thanks!